ethercreative / seo

SEO utilities including a unique field type, sitemap & redirect manager
MIT License
269 stars 96 forks source link

[FR] Sitemap.xml graphql endpoint #396

Closed maximilian-schwarz closed 2 years ago

maximilian-schwarz commented 2 years ago

Description

I think it's very important to have the possibility get the sitemap via Graphql to generate a sitemap.xml for headless project wiht NuxtJS oder NextJS.

Maybe the response can look like this:

"sitemap": {
  "filename": "sitemap_pages.xml",
  "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?> <urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"><url><loc>http://www.example.com/foo.html</loc><lastmod>2018-06-04</lastmod></url></urlset>"
}
alexjcollins commented 2 years ago

Hey @maximilian-schwarz - we're in the process of rewriting the plugin for Craft 4, so we'll absolutely consider this.

In the meantime, certainly with NextJS, you can use rewrites to map to the URL of your craft install.

Something like this:

async rewrites() {
  return [
    {
      source: '/sitemap.xml',
      destination: `${process.env.ADMIN_URL}/sitemap.xml`,
    },
    {
      source: '/sitemap:path.xml',
      destination: `${process.env.ADMIN_URL}/sitemap:path.xml`,
    },
    {
      source: '/robots.txt',
      destination: `${process.env.ADMIN_URL}/robots.txt`,
    },
  ];
},
maximilian-schwarz commented 2 years ago

Thanks for the tip 👍🏻