next-sitemap
next-sitemap copied to clipboard
Support Google News Sitemaps
Is your feature request related to a problem? Please describe. I am using next.js to build local news websites. I want to ensure they are configured properly for SEO and Google News. Google News requires a specific sitemap format with special fields in order to have your news website populate in Google News.
Describe the solution you'd like
In order to support this, next-sitemap
would need to allow the population of nested fields. A Google News sitemap requires some specific nested fields. Here's an example from The New York Times:
<url>
<loc>
https://www.nytimes.com/2019/09/30/learning/lesson-of-the-day-kehinde-wileys-times-square-monument-thats-no-robert-e-lee.html
</loc>
<lastmod>2021-03-05T20:38:12Z</lastmod>
<news:news>
<news:publication>
<news:name>The New York Times</news:name>
<news:language>en-US</news:language>
</news:publication>
<news:publication_date>2019-09-30T08:00:03Z</news:publication_date>
<news:title>
Lesson of the Day: ‘Kehinde Wiley’s Times Square Monument: That’s No Robert E. Lee’
</news:title>
</news:news>
<image:image>
<image:loc>
https://static01.nyt.com/images/2019/09/27/arts/27kehinde3/27kehinde3-articleLarge.jpg
</image:loc>
</image:image>
</url>
Ideally, when returning an object for a URL either in the transform
function or in a dynamic sitemap, I could populate these fields:
return {
loc: "/2019/09/30/learning/lesson-of-the-day-kehinde-wileys-times-square-monument-thats-no-robert-e-lee.html",
lastmod: "2021-03-05T20:38:12Z",
news: {
publication: {
name: "The New York Times",
language: "en-US"
},
publication_date: "2019-09-30T08:00:03Z",
title: "Lesson of the Day: 'Kehinde Wiley’s Times Square Monument: That’s No Robert E. Lee'"
},
image: {
loc: "https://static01.nyt.com/images/2019/09/27/arts/27kehinde3/27kehinde3-articleLarge.jpg"
}
}
Describe alternatives you've considered I could generate this XML file on my own through next.js, but it would be nice to use the same library I'm using to generate the overall sitemap.
Hi, any updates ?
hello @iamvishnusankar ,
For my project I need the Support of Google News Sitemaps. By looking at the code here, I saw that you are doing a test about "alternateRefs". I would like to update this part by adding new case for news such as the object below:
news: {
publication: {
name: "The New York Times",
language: "en-US"
},
publication_date: "2019-09-30T08:00:03Z",
title: "Lesson of the Day: 'Kehinde Wiley’s Times Square Monument: That’s No Robert E. Lee'"
},
image: {
loc: "https://static01.nyt.com/images/2019/09/27/arts/27kehinde3/27kehinde3-articleLarge.jpg"
}
If you agree with that I can do a PR to provide this functionality. What do you think ?
Thanks for the package!
@b-barry Feel free to submit a PR anytime :)
For anyone also stuck needing nested field support, I've been able to work around it by passing a template literal into in the parent field eg:
{
"image:image": `
<image:loc>${imgUrl}</image:loc>
<image:title>${imgTitle}</image:title>
<image:caption>${imgCaption}</image:caption>
`
}
Hi, any updates?
Nested field support is also needed for video sitemaps. video:video....</video:video> so the solution https://github.com/iamvishnusankar/next-sitemap/pull/220 does't seem to work
return {
loc: path, // => this will be exported as http(s)://<config.siteUrl>/<path>
changefreq: config.changefreq,
priority: config.priority,
lastmod,
alternateRefs: config.alternateRefs ?? [],
"news:news": `
<news:publication>
<news:name>${name}</news:name>
<news:language>en</news:language>
</news:publication>
<news:publication_date>${dateString}</news:publication_date>
<news:title>${title}</news:title>
`
}
Hi everybody Is this feature implemented? is there any pending PR? Thanks
Hi, I was able to create a PR supporting every mentioned feature: google news, image and video sitemap. Please create a feedback as soon as possible (cc @iamvishnusankar )
Great @zuffik I suppose is this one https://github.com/iamvishnusankar/next-sitemap/pull/437 Can you add in the doc how to use that? Do you need to call a method or automatically will identify images? Thanks
@fescobar thanks for feedback, I updated the docs. You can use it by adding news
, images
or videos
to the sitemap entry (see also ts reference):
https://github.com/iamvishnusankar/next-sitemap/blob/34c0096027cb92786a9c416aeccc2cd67e32f9ae/packages/next-sitemap/src/interface.ts#L282-L293
Please consider merging this PR, this is needed very badly for the Google News Sitemaps.
Closing this issue due to inactivity.
R U kidding me?
@zuffik Sorry, the inactivity was flagged by stale bot. I'm reviewing your PR now.