nextjs-sitemap-generator icon indicating copy to clipboard operation
nextjs-sitemap-generator copied to clipboard

generated XML contains dynamic route path

Open FunctionDJ opened this issue 3 years ago • 2 comments

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

FunctionDJ avatar Jan 18 '21 17:01 FunctionDJ

Which version are you using?

IlusionDev avatar Jan 22 '21 08:01 IlusionDev

"nextjs-sitemap-generator": "^1.3.0",

FunctionDJ avatar Jan 23 '21 23:01 FunctionDJ