Input document:
<entry xmlns="http://www.w3.org/2005/Atom">
<id>urn:uuid:1234</id>
<updated>2012-01-20T11:30:11-05:00</updated>
<published>2011-12-29T15:44:11-05:00</published>
<link href="?id=urn:uuid:1234" rel="edit" type="application/atom+xml"/>
<title>Title</title>
<category scheme="http://uri/categories" term="category"/>
<fake:fake xmlns:fake="http://fake/" attr="val"/>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<p>Blah</p>
</div>
</content>
</entry>
<!-- more entries -->
I want the output to be exactly the same, but with non-Atom elements like <fake:fake xmlns:fake="http://fake/" attr="val"/> stripped out. This is what I have, which doesn't work at all, just giving me the same input back:
declare namespace atom = "http://www.w3.org/2005/Atom";
<feed>
<title>All Posts</title>
{
for $e in collection('/db/entries')/atom:entry
return
if
(namespace-uri($e) = "http://www.w3.org/2005/Atom")
then
$e
else
''
}
</feed>
What am I doing wrong?
You can try the following query on try.zorba-xquery.com:
let $entry := <entry xmlns="http://www.w3.org/2005/Atom">
<id>urn:uuid:1234</id>
<updated>2012-01-20T11:30:11-05:00</updated>
<published>2011-12-29T15:44:11-05:00</published>
<link href="?id=urn:uuid:1234" rel="edit" type="application/atom+xml"/>
<title>Title</title>
<category scheme="http://uri/categories" term="category"/>
<fake:fake xmlns:fake="http://fake/" attr="val"/>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<p>Blah</p>
</div>
</content>
</entry>
return {
delete nodes $entry//*[not(namespace-uri(.) = "http://www.w3.org/2005/Atom")];
$entry
}
The following version is more portable:
let $entry := <entry xmlns="http://www.w3.org/2005/Atom">
<id>urn:uuid:1234</id>
<updated>2012-01-20T11:30:11-05:00</updated>
<published>2011-12-29T15:44:11-05:00</published>
<link href="?id=urn:uuid:1234" rel="edit" type="application/atom+xml"/>
<title>Title</title>
<category scheme="http://uri/categories" term="category"/>
<fake:fake xmlns:fake="http://fake/" attr="val"/>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<p>Blah</p>
</div>
</content>
</entry>
return
copy $new-entry := $entry
modify (delete nodes $new-entry//*[not(namespace-uri(.) = "http://www.w3.org/2005/Atom")])
return $new-entry
Sort of a round-about way of doing it but this ended up working:
declare default element namespace "http://www.w3.org/2005/Atom";
<feed>
<title>All Posts</title>
{
for $entry in collection('/db/entries')/entry
return
element{node-name($entry)}{
$entry/#*,
for $child in $entry//*[namespace-uri(.) = "http://www.w3.org/2005/Atom"]
return $child
}
}
</feed>
Waiting for the time limit to expire and then I'll accept it as an answer.
Related
I want to set locale in script google map like this:
<script defer src={`https://maps.googleapis.com/maps/api/js?key=key&libraries=places&language=${locale}`}/>
but how can i get to locale in Document nextJS?
useRouter doesnot work in Document component.
export default function Document() {
return (
<Html>
<Head>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<script defer src={`https://maps.googleapis.com/maps/api/js?key=key&libraries=places&language=${locale}`}/>
</Head>
<body>
<Main />
<NextScript />
</body>
</Html>
);
}
You can access locale in this.props.locale.
In my project this locale uses in this case:
<Html lang={this.props.locale}>
/....
I use class component in _document.
In your variant you can access locale just in props.
import { Html, Head, Main, NextScript } from "next/document";
export default function Document(props: DocumentProps) {
return (
<Html lang={props.locale}>
<Head />
<body>
<Main />
<NextScript />
</body>
</Html>
);
}
It works if you already add i18n config, and inject it to next config.
https://codesandbox.io/p/sandbox/musing-noether-7loye1?file=%2Fpages%2F_document.tsx&selection=%5B%7B%22endColumn%22%3A9%2C%22endLineNumber%22%3A11%2C%22startColumn%22%3A9%2C%22startLineNumber%22%3A11%7D%5D
Here is my code I want to update the meta content based on the query parameter.
For Example localhost:3000/in
I need to fetch the meta content for India and need to update on .
But I can't fetch the query parameters on getInitialProps. how to get query params inside getInitialProps?
function StartApp({ Component, pageProps, initialAsideLeftHandler }) {
return <>
<Provider store={store}>
<Head>
<title>{initialAsideLeftHandler[2].values}</title>
<meta name="title" content={initialAsideLeftHandler[2].values} />
<meta name="description" content={initialAsideLeftHandler[1].values} />
<link rel="icon" href="/favicon.ico" />
</Head>
<Header/>
<Component {...pageProps} />
<Footer />
</Provider>
</>
}
StartApp.getInitialProps = async ({query}) => {
let parameter = {
"countryCode": "in",
"slug": "home",
}
let data = await getMetaContent(parameter);
return { initialAsideLeftHandler: data }
}
Team, I need your help /expertise to retrieve node value by traversing an xml response. I would like to use this an integration middleware.
Input file sample:
<feed xmlns="http://www.w3.org/2005/Atom"
xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
xml:base="https://api12preview.sapsf.eu:443/odata/v2/">
<title type="text">PerEmail</title>
<id>https://api12preview.sapsf.eu:443/odata/v2/PerEmail</id>
<updated>2022-11-09T13:58:27Z</updated>
<link href="PerEmail" rel="self" title="PerEmail"/>
<entry>
<id>https://api12preview.sapsf.eu:443/odata/v2/PerEmail(emailType='54139',personIdExternal='GI00152188')</id>
<title type="text"/>
<updated>2022-11-09T13:58:27Z</updated>
<author>
<name/>
</author>
<link href="PerEmail(emailType='54139',personIdExternal='GI00152188')"
rel="edit"
title="PerEmail"/>
<category scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"
term="SFOData.PerEmail"/>
<content type="application/xml">
< properties>
<d:personIdExternal>GI00152188</d:personIdExternal>
<d:emailAddress>someone#test_boehringer.com</d:emailAddress>
</m:properties>
</content>
</entry>
<entry>
<id>https://api12preview.sapsf.eu:443/odata/v2/PerEmail(emailType='54139',personIdExternal='GI00453224')</id>
<title type="text"/>
<updated>2022-11-09T13:58:27Z</updated>
<author>
<name/>
</author>
<link href="PerEmail(emailType='54139',personIdExternal='GI00453224')"
rel="edit"
title="PerEmail"/>
<category scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"
term="SFOData.PerEmail"/>
<content type="application/xml">
<m:properties>
<d:personIdExternal>GI00453224</d:personIdExternal>
<d:emailAddress>someone#test_boehringer.com</d:emailAddress>
</m:properties>
</content>
</entry>
<link href="https://api12preview.sapsf.eu:443/odata/v2/PerEmail?$select=emailAddress,personIdExternal&$filter=emailType%20eq%2054139&$skiptoken=eyJzdGFydFJvdyI6MTAwMCwiZW5kUm93IjoyMDAwfQ=="
rel="next"/>
</feed>
Out of this response or xml Xquery should run through all 'entry' node and pick values of node 'personIdExternal' and I'm expecting result like this
<element>
<personIdExternal>GI00152188</personIdExternal>
<personIdExternal>GI00453224</personIdExternal>
</element>
I have tried something below code earlier but it's not working here, and I suspect this is due to namespace in the source xml. My knowledge is limited in XQuery - Please help
{let $input:= /entry
for $i in $input/properties
return
<element>
<personIdExternal>{i/personIdExternal/text()}</personIdExternal>
</element>}
/entry doesn't select anything because the entry elements aren't at the top level, and they're in a namespace.
$input/properties is wrong because the properties element isn't a child of entry and it's in a namespace.
i doesn't select anything, it should be $i
personIdExternal doesn't select anything because it's in a namespace.
You just need
<element>{//*:personIdExternal}</element>
Running into an issue with getting my meta tags working properly with NextJS.
Here is an online page : https://www.acaciapp.com/action/alimentation/eviter-boire-jus-fruits-presses/O4tkFjvta1c1B8XzFC3j
The info is populated on the head tag but is not parsed by social media (using https://www.opengraph.xyz/ for example) => it does not return the title, nor the description, nor the og:image.
Here is my code :
_app.js
export default function MyApp(props) {
const { Component, emotionCache = clientSideEmotionCache, pageProps } = props;
return (
<CacheProvider value={emotionCache}>
<Head>
<meta name="viewport" content="initial-scale=1, width=device-width" />
<meta name="author" content="Maxime Courtaigne" />
<title key="title">acacia.</title>
</Head>
<StyledEngineProvider injectFirst>
<ThemeProvider theme={theme}>
<AuthProvider>
<ActionProvider>
<ObjectiveProvider>
<PointsProvider>
{/* <PercentProvider> */}
{/* CssBaseline kickstart an elegant, consistent, and simple baseline to build upon. */}
<CssBaseline />
<Component {...pageProps} />
{/* </PercentProvider> */}
</PointsProvider>
</ObjectiveProvider>
</ActionProvider>
</AuthProvider>
</ThemeProvider>
</StyledEngineProvider>
</CacheProvider>
);
}
_document.js :
export default class MyDocument extends Document {
render() {
return (
<Html lang="fr">
<Head>
{/* PWA primary color */}
<meta name="theme-color" content={theme.palette.primary.main} />
<link rel="shortcut icon" href="/favicon.ico" />
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=Caveat:wght#700&family=Karla:wght#300;400;600;800&display=swap"
/>
{/* Inject MUI styles first to match with the prepend: true configuration. */}
{this.props.emotionStyleTags}
</Head>
<body>
<Main />
<NextScript />
</body>
</Html>
);
}
}
A specific page :
function Action({actionData, actionId, params}) {
// some functions, etc..
return (
<div className={styles.actionPage}>
<Meta
title={`${actionData.title} | acacia`}
desc={actionData.description.substring(0,150)}
canonical={`https://www.acaciapp.com/action/${params.category}/${params.slug}/${params.id}`}
/>
// Some content
</div>
}
The Meta component :
// Header of every page
import Head from "next/head"
import Script from "next/script"
function Meta(props) {
return (
<Head>
<title >{props.title}</title> {/* 40-50 char */}
<meta name="description" content={props.desc} /> {/* 150-160 char */}
<meta property="og:type" content="website" />
{props.canonical && <link rel="canonical" href={`${props.canonical}`} key="canonical" />}
<meta name="og:title" property="og:title" content={props.title} />
<meta name="og:description" property="og:description" content={props.desc} />
<meta property="og:site_name" content="acacia" />
<meta property="og:url" content={`${props.canonical}`} />
<meta name="twitter:card" content="summary" />
<meta name="twitter:title" content={props.title} />
<meta name="twitter:description" content={props.desc} />
<meta name="twitter:site" content="#acacia_app" />
<meta name="twitter:creator" content="#acacia_app" />
<link rel="icon" type="image/png" href="/favicon.ico" />
<link rel="apple-touch-icon" href="/favicon.ico" />
{props.image ?
(<meta property="og:image" content={`${props.image}`} />) :
(<meta property="og:image" content="https://firebasestorage.googleapis.com/v0/b/acacia-44ebf.appspot.com/o/ogImages%2Fog-home.png?alt=media&token=81fc5d4e-db1b-4cd2-93ff-cbb27f8b8753" />)}
{props.image && <meta name="twitter:image" content={`${props.image}`} />}
{props.robot && <meta name="robots" content={props.robot} />}
{props.css && <link rel="stylesheet" href={`${props.css}`}/>}
{props.js && <Script type="text/javascript" src={`${props.js}`} />}
</Head>
)
}
export default Meta
Is it an overide issue with __document or __app ? should I add "key" tags ?
Thanks !
----- EDIT -----
I think the issue comes from the __document initial rendering method that is quite inunderstandable for me :/. Here is the code :
import * as React from 'react';
import Document, { Html, Head, Main, NextScript } from 'next/document';
import createEmotionServer from '#emotion/server/create-instance';
import theme from '../utility/theme';
import createEmotionCache from '../utility/createEmotionCache';
export default class MyDocument extends Document {
render() {
return (
<Html lang="fr">
<Head>
{/* PWA primary color */}
<meta charSet="utf-8" />
<meta key="robots" name="robots" content="index, follow" />
<meta key="themeColor" name="theme-color" content={theme.palette.primary.main} />
<link key="shortcutIcon" rel="shortcut icon" href="/favicon.ico" />
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=Caveat:wght#700&family=Karla:wght#300;400;600;800&display=swap"
/>
{/* Inject MUI styles first to match with the prepend: true configuration. */}
{this.props.emotionStyleTags}
</Head>
<body>
<Main />
<NextScript />
</body>
</Html>
);
}
}
// `getInitialProps` belongs to `_document` (instead of `_app`),
// it's compatible with static-site generation (SSG).
MyDocument.getInitialProps = async (ctx) => {
// Resolution order
//
// On the server:
// 1. app.getInitialProps
// 2. page.getInitialProps
// 3. document.getInitialProps
// 4. app.render
// 5. page.render
// 6. document.render
//
// On the server with error:
// 1. document.getInitialProps
// 2. app.render
// 3. page.render
// 4. document.render
//
// On the client
// 1. app.getInitialProps
// 2. page.getInitialProps
// 3. app.render
// 4. page.render
const originalRenderPage = ctx.renderPage;
// You can consider sharing the same emotion cache between all the SSR requests to speed up performance.
// However, be aware that it can have global side effects.
const cache = createEmotionCache();
const { extractCriticalToChunks } = createEmotionServer(cache);
ctx.renderPage = () =>
originalRenderPage({
enhanceApp: (App) =>
function EnhanceApp(props) {
return <App emotionCache={cache} {...props} />;
},
});
const initialProps = await Document.getInitialProps(ctx);
// This is important. It prevents emotion to render invalid HTML.
// See https://github.com/mui/material-ui/issues/26561#issuecomment-855286153
const emotionStyles = extractCriticalToChunks(initialProps.html);
const emotionStyleTags = emotionStyles.styles.map((style) => (
<style
data-emotion={`${style.key} ${style.ids.join(' ')}`}
key={style.key}
// eslint-disable-next-line react/no-danger
dangerouslySetInnerHTML={{ __html: style.css }}
/>
));
return {
...initialProps,
emotionStyleTags,
};
};
Found out the solution. It has nothing to do with the render method within __document nor __app.
The getStaticProps and getServerSideProps was actually not rendering the proper HTML because of a conditional rendering in the dynamic page.
I was doing :
if (loadingUser) return <Loader/>
return (
// main render of the page
)
By deleting this conditionnal rendering, everything is working perfectly
How to describe comments tree with Atom/RSS?
There's a draft standard to extend Atom with threaded discussions, but that's no longer active. This is a feed with comments:
<feed xmlns="http://www.w3.org/2005/Atom"
xmlns:thr="http://purl.org/syndication/thread/1.0">
<id>http://www.example.org/myfeed</id>
<title>My Example Feed</title>
<updated>2005-07-28T12:00:00Z</updated>
<link href="http://www.example.org/myfeed" />
<author><name>James</name></author>
<entry>
<id>tag:example.org,2005:1</id>
<title>My original entry</title>
<updated>2006-03-01T12:12:12Z</updated>
<link
type="application/xhtml+xml"
href="http://www.example.org/entries/1" />
<summary>This is my original entry</summary>
</entry>
<entry>
<id>tag:example.org,2005:1,1</id>
<title>A response to the original</title>
<updated>2006-03-01T12:12:12Z</updated>
<link href="http://www.example.org/entries/1/1" />
<thr:in-reply-to
ref="tag:example.org,2005:1"
type="application/xhtml+xml"
href="http://www.example.org/entries/1"/>
<summary>This is a response to the original entry</summary>
</entry>
</feed>
You can use html in RSS but < and > must be present as < and >
<description>
...
<!-- comments -->
<ul>
<li>comment1</li>
<li>comment2</li>
<li>comment3</li>
<li>comment4</li>
<ul>
</description>