IlusionDev / nextjs-sitemap-generator

Generate sitemap.xml from nextjs pages

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Documentation: getStaticPaths Usage Not Clear

jhoffmcd opened this issue · comments

I have this plugin working on a fully statically exported Next.js project, and it was very simple to set up. My site uses getStaticPaths for all the dynamic pages and part of the documentation here had me scratching my head a bit. I have a few questions about it.

Where is BUILD_ID used in the example?

As you can see from this example, BUILD_ID is set but then doesn't seem to be called anywhere:

const sitemap = require("nextjs-sitemap-generator");
const fs = require("fs");

const BUILD_ID = fs.readFileSync(".next/BUILD_ID").toString();

sitemap({
  baseUrl: "https://example.com",
  pagesDirectory: __dirname + "/.next/serverless/pages",
  targetDirectory: "public/",
  ignoredExtensions: ["js", "map"],
  ignoredPaths: ["[fallback]"],
});

Can't I just point out the output directory and be done?

For my fully static site, I just did this and it worked. I use getStaticPaths all over the place, am I missing something?

sitemap({
  baseUrl: process.env.NEXT_PUBLIC_APP_BASE_URL,
  pagesDirectory: path.resolve(
    __dirname,
    '..',
    'out'
  ),
  targetDirectory: 'out/',
  ignoredPaths: ['assets']
});

I had to exclude the assets directory but other than that all my pages are represented.

Can we update the documentation around static export usage and requirements? Are there different use cases to consider here?

Hey, you right some information had been lost between updates. I will fix it.

Thanks @IlusionDev

For anyone interested in what we actually ended up with in config:

sitemap({
  baseUrl: process.env.NEXT_PUBLIC_APP_BASE_URL,
  pagesDirectory: path.resolve(
    __dirname,
    '..',
    'out'
  ),
  targetDirectory: 'out/',
  ignoreIndexFiles: true,
  ignoredPaths: ['/assets'],
  ignoredExtensions: ['png', 'jpg', 'xml', 'txt']
});