-
Notifications
You must be signed in to change notification settings - Fork 4
/
your_nextjs_sitemap_generator.js
50 lines (48 loc) · 1.33 KB
/
your_nextjs_sitemap_generator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const sitemap = require("nextjs-sitemap-generator");
const path = require("path");
const prettier = require("prettier");
const fs = require("fs");
(async () => {
try {
await sitemap({
baseUrl: "https://kevinpeters.net",
ignoredPaths: [
"/404",
"/ads",
"/index",
"/money",
"/personal-branding-faang-banner",
"/remote-mdx-1",
"/robots",
"/roll-safe",
"/sitemap",
"/spongebob-searching",
"/sw",
"/vue-js-review-of-2017-preview",
],
extraPaths: [],
pagesDirectory: __dirname + "\\out",
targetDirectory: "public/",
sitemapFilename: "sitemap.xml",
nextConfigPath: __dirname + "\\next.config.js",
ignoredExtensions: ["png", "jpg"],
pagesConfig: {
"/login": {
priority: "0.5",
changefreq: "daily",
},
},
sitemapStylesheet: [],
});
const sitemapPath = path.resolve(__dirname, "./public", "./sitemap.xml");
const xmlContent = fs.readFileSync(sitemapPath).toString();
const result = prettier.format(xmlContent, {
parser: "xml",
xmlWhitespaceSensitivity: "ignore",
});
fs.writeFileSync(sitemapPath, result);
console.log(`✅ sitemap.xml generated!`);
} catch (e) {
// Deal with the fact the chain failed
}
})();