next-sitemap icon indicating copy to clipboard operation
next-sitemap copied to clipboard

Support Google News Sitemaps

Open TylerFisher opened this issue 3 years ago • 12 comments

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.

TylerFisher avatar Mar 05 '21 20:03 TylerFisher

Hi, any updates ?

sonnh58 avatar Jun 18 '21 04:06 sonnh58

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 avatar Oct 03 '21 16:10 b-barry

@b-barry Feel free to submit a PR anytime :)

iamvishnusankar avatar Oct 03 '21 16:10 iamvishnusankar

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>
          `
}

searleb avatar Nov 22 '21 06:11 searleb

Hi, any updates?

antonfrolovsky avatar Jan 23 '22 23:01 antonfrolovsky

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

grangier avatar Jan 24 '22 12:01 grangier

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>
        `
      }

eugenehp avatar Jan 26 '22 08:01 eugenehp

Hi everybody Is this feature implemented? is there any pending PR? Thanks

fescobar avatar Jun 13 '22 14:06 fescobar

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 )

zuffik avatar Jul 10 '22 09:07 zuffik

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 avatar Jul 10 '22 20:07 fescobar

@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

zuffik avatar Jul 11 '22 11:07 zuffik

Please consider merging this PR, this is needed very badly for the Google News Sitemaps.

Kyoss79 avatar Sep 15 '22 21:09 Kyoss79

Closing this issue due to inactivity.

github-actions[bot] avatar Mar 07 '23 04:03 github-actions[bot]

R U kidding me?

zuffik avatar Mar 07 '23 05:03 zuffik

@zuffik Sorry, the inactivity was flagged by stale bot. I'm reviewing your PR now.

iamvishnusankar avatar Mar 07 '23 10:03 iamvishnusankar