Generate a video sitemap for Next.js

35 views Asked by At

I'm currently working on a project where I'm able to generate a sitemap successfully. I've created several sitemaps, and one of them is named "videos". After some research, I discovered that Google recommends using a dedicated sitemap for videos.

Here's an example of the structure recommended by Google for a video sitemap:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
    xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
  <url>
    <loc>https://www.example.com/videos/some_video_landing_page.html</loc>
    <video:video>
      <video:thumbnail_loc>https://www.example.com/thumbs/123.jpg</video:thumbnail_loc>
      <video:title>Lizzi is painting the wall</video:title>
      <video:description>
        Gary is watching the paint dry on the wall Lizzi painted.
      </video:description>
      <video:player_loc>
        https://player.vimeo.com/video/987654321
      </video:player_loc>
    </video:video>
  </url>
</urlset>

After many hours of research, I couldn't find any documentation regarding generating a video sitemap with Next.js that allows customizing the tags. Currently, my code looks like this:

if (id === "videos") {
    if (Array.isArray(video)) {
        return video.map((video) => ({
            url: `${baseUrl}/tv/${video.id}/${helpers.formatTextUrl(video.title)}`,
            hello: new Date().toISOString(),
            changeFrequency: "daily",
            priority: 0.5,
        }));
    }
}

The resulting output looks like this:

<url>
<loc>http://exemple.com/tv/68/070324-le-journal-de-maritima-tv</loc>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>

I would like to know if anyone has managed to modify the tags of the XML sitemap generated by Next.js

0

There are 0 answers