-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathnext-sitemap.config.js
More file actions
52 lines (49 loc) · 1.51 KB
/
next-sitemap.config.js
File metadata and controls
52 lines (49 loc) · 1.51 KB
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
51
52
const fs = require("fs");
const path = require("path");
let archivedSlugs = [];
try {
const jsonPath = path.join(__dirname, "archived-rules.json");
archivedSlugs = JSON.parse(fs.readFileSync(jsonPath, "utf-8"));
console.log(`📋 Sitemap: Loaded ${archivedSlugs.length} archived slugs from ${jsonPath}`);
if (archivedSlugs.length > 0) {
console.log(`📋 Sitemap: Sample slugs: ${archivedSlugs.slice(0, 3).join(", ")}`);
}
} catch (err) {
console.warn("⚠️ archived-rules.json not found — archived rules will not be excluded from sitemap");
console.warn("⚠️ Error:", err.message);
}
/** @type {import('next-sitemap').IConfig} */
module.exports = {
siteUrl: `${process.env.NEXT_PUBLIC_SITE_URL || "https://www.ssw.com.au"}${process.env.NEXT_PUBLIC_BASE_PATH}`,
changefreq: "daily",
priority: 0.7,
sitemapBaseFileName: "sitemap-index",
sitemapSize: 5000,
generateRobotsTxt: true,
output: "standalone",
outDir: "public/",
transform: async (config, path) => {
if (path.includes("/api") || path.includes("/icon.ico")) {
return null;
}
// Exclude archived rules from sitemap
const slug = path.replace(/^\//, "").replace(/\/$/, "");
if (archivedSlugs.includes(slug)) {
return null;
}
return {
loc: path,
changefreq: config.changefreq,
priority: config.priority,
lastmod: config.lastmod || new Date().toISOString(),
};
},
robotsTxtOptions: {
policies: [
{
userAgent: "*",
allow: "/",
},
],
},
};