pedrosousa13 / blog.psousa.dev-comments

comments for blog.psousa.dev
0 stars 0 forks source link

posts/generate-dynamic-sitemap-with-storyblok-and-next-js #2

Open utterances-bot opened 3 years ago

utterances-bot commented 3 years ago

Generate Dynamic Sitemap with Storyblok and Next.js | Pedro Sousa

Programming, Tech and other random blurbs

https://blog.psousa.dev/posts/generate-dynamic-sitemap-with-storyblok-and-next-js

brada1703 commented 3 years ago

Sweet post, Pedro! Thanks :)

tobias-zucali commented 1 year ago

Thanks a lot for this post, was a great starting point! I just added the last published date to the sitemap

const generateSitemap = (posts, url) => {
  return `<?xml version="1.0" encoding="UTF-8"?>
    <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    ${posts
      .map(
        ({ slug, published_at }) => `
      <url>
        <loc>https://${url}/${slug}</loc>
        <lastmod>${published_at}</lastmod>
      </url>`,
      )
      .join("")}
    </urlset>`;
};

... and used the same technique for robots.txt in order to avoid the hardcoded URL.