Closed laurencefass closed 9 months ago
here its work
New Meta API conveniently generates Open Graph Meta Tags.
export const metadata = { openGraph: { title: 'Next.js', description: 'The React Framework for the Web', url: 'https://nextjs.org', siteName: 'Next.js', images: [ { url: 'https://nextjs.org/og.png', width: 800, height: 600, }, { url: 'https://nextjs.org/og-alt.png', width: 1800, height: 1600, alt: 'My custom alt', }, ], locale: 'en-US', type: 'website', }, };
https://nextjs.org/docs/app/api-reference/functions/generate-metadata#opengraph
The only version of this that functions for me so far is getStaticProps
, which is not compatible with our use of the framework (standalone PWAs.)
@AlbinoGeek How exactly generating standalone static files prevents you from making PWAs?
Possible Solution.
I have spent days looking at this now and I am not convinced that the mechanism for pages overriding _app.tsx metadata by inclusion of a in individual pages works for facebook sharing . While the overrides show in the browser debugger they are not picked up by facebook debugger.
To workaround this limitation and solve this particular issue I have been able to expose metadata to facebook debugger by having a single block in _app.tyx and pass page specific metata as props in getServerSideProps. Guessing would also work for getStaticProps.
page.tsx
export async function getServerSideProps(context) { return { props: { title: "Page one! ", description: "Page One metadata", image: `${hostURL}/images/page_one_image.jpg` } } } export default function Page() { return <div> <h1>Page One</h1> </div> }
_app.tsx
function MyApp({ Component, pageProps }: AppProps) { let title = pageProps.title ? pageProps.title : "Default metatags "; let description = pageProps.description ? pageProps.description : "Default description"; let image = pageProps.image ? pageProps.image : `${hostURL}/image/default_image.jpg`; return <> <Head> <meta/> <other tags/> </Head> </>
thank you for this soln... this is actually quite elegant as I no longer need to have 'Head' elements on each page - I just use staticProps to pass whatever I need to pre-render. Works amazing with all sorts of social sharing and optimises SEO. GOLD
@Fastbac65 thanks it worked for me :D
time to close this
@landsman it's a bug lol we did some kind of workaround :)
Hi everyone!
While the overrides show in the browser debugger they are not picked up by facebook debugger.
Was anybody able to verify if the <meta>
output in the HTML is any different from the solution above versus how there were using next/head
in individual pages? Tough to say if this was ever an actual bug versus if Facebook Debugger was interpreting <meta>
tags differently.
I am having the same exact issue
Hi everyone,
I will move this to the Discussions for the time being! If you come across a similar issue, please submit a new bug report.
Verify canary release
Provide environment information
sorry this is not working.
i am running
nextjs 12 node 16.12.1 yarn 1.22.5
What browser are you using? (if relevant)
chrome
How are you deploying your application? (if relevant)
VPS
Describe the Bug
Summary: I am trying to create fb and twitter metadata for my whole site by defining a
with metadata in _app.js with overrides for specific components using the identical set of tags with some local overrides.Implementation: I have a two page site with _app.js, one.js and two.js files. I have added a
section into _app.js file and a section in one.js with some overrides. I have used the keys to ensure that duplicates are not made and when i load the pages in the browser I can see that this works correctly and component specific overrides are presented.The relevant metadata is as follows and is contained in both _app.js and one.js (but not two.js which I expect to use _app.js metadata). Use of variables enables me to use an identical metadata and set component specific overrides.
Result:
Summary: things work as expected in the browser but facebook debugger is not picking up the component specific changes.
In the browser I can see that the correct metadata is loaded for one.js (presenting the component specific overrides) and two.js (presenting the metadata from _app.js). However the facebook debugger is only picking up metadata from _app.js not from one.js - so all pages have the same metadata.
Expected Behavior
Both the facebook debugger and the client browser to load the same metadata. Facebook debugger is somehow not collecting the page specific metadata overrides.
To Reproduce
I have a live site running here:
https://next18.syntapse.co.uk/two doesnt define its own metadata so loads default tags from _app.js using keys to avoid duplication
https//next18.syntapse.co.uk/one loads overrided tags using keys to avoid duplication
This works as expected in the browser. Load this into a browser and note the differences in metadata. Note the metadata changes from the default to the override.
Load this into the facebook debugger and note that /one loads the same metadata as /two and also / url.