nextjs-sitemap-generator
nextjs-sitemap-generator copied to clipboard
generated XML contains dynamic route path
This is an excerpt of the XML file i get:
<url>
<loc>https://example.com/blog/foo</loc>
<lastmod>2021-01-18</lastmod>
</url>
<url>
<loc>https://example.com/blog/bar</loc>
<lastmod>2021-01-18</lastmod>
</url>
<url>
<loc>https://example.com/blog/[slug]</loc>
<lastmod>2021-01-18</lastmod>
</url>
<url>
<loc>https://example.com/blog</loc>
<lastmod>2021-01-18</lastmod>
</url>
You can see the /blog/[slug]
entry. I don't think this is intentional/correct since that's not a path a browser or crawler can access. Only the other 3 routes should be rendered.
Here is my scripts/sitemap-generator.js
:
const sitemap = require("nextjs-sitemap-generator");
sitemap({
baseUrl: "https://example.com",
pagesDirectory: process.cwd() + "/.next/server/pages",
targetDirectory: "out/"
});
console.log("✅ sitemap.xml generated!");
Since the site is fully static, i call this script using package.json
:
{
"scripts": {
"dev": "next dev",
"build": "next build && next export && npm run sitemap",
"serve": "npm run build && serve ./out/",
"start": "next start",
"sitemap": "node scripts/sitemap-generator.js"
}
}
Which version are you using?
"nextjs-sitemap-generator": "^1.3.0",