-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathnext-sitemap.config.js
104 lines (95 loc) · 2.79 KB
/
next-sitemap.config.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
const fs = require("fs");
const path = require("path");
/** @type {import('next-sitemap').IConfig} */
module.exports = {
siteUrl: process.env.SITE_URL,
changefreq: "daily",
priority: 0.7,
sitemapSize: 5000,
generateRobotsTxt: true,
output: "standalone",
additionalPaths: async () => {
const otherURLs = [
"https://blog.ssw.com.au/",
"https://www.ssw.com.au/rules/",
];
const getAllFiles = (dirPath, arrayOfFiles) => {
const files = fs.readdirSync(dirPath);
arrayOfFiles = arrayOfFiles || [];
files.forEach((file) => {
if (fs.statSync(path.join(dirPath, file)).isDirectory()) {
arrayOfFiles = getAllFiles(path.join(dirPath, file), arrayOfFiles);
} else {
arrayOfFiles.push(path.join(dirPath, file));
}
});
return arrayOfFiles;
};
const newsletterUploadsDir = path.join(
__dirname,
"public",
"images",
"newsletter-uploads"
);
const newsletterUploads = getAllFiles(newsletterUploadsDir).map((file) => ({
loc: `/images/newsletter-uploads/${path.relative(newsletterUploadsDir, file).replace(/\\/g, "/")}`,
changefreq: "daily",
priority: 0.7,
lastmod: new Date().toISOString(),
}));
const otherURLsMapped = otherURLs.map((url) => ({
loc: url,
changefreq: "daily",
priority: 0.7,
lastmod: new Date().toISOString(),
trailingSlash: true,
}));
return [...otherURLsMapped, ...newsletterUploads];
},
transform: async (config, path) => {
if (path.includes("/home")) {
return {
loc: path.replace("/home", "/"),
changefreq: config.changefreq,
priority: 1.0,
lastmod: config.lastmod || new Date().toISOString(),
};
} else if (path.includes("/500") || path.includes("/404")) {
return null;
}
return {
loc: path,
changefreq: config.changefreq,
priority: config.priority,
lastmod: config.lastmod || new Date().toISOString(),
};
},
robotsTxtOptions: {
policies: [
{
userAgent: "*",
allow: "/",
disallow: [
"/404",
"/500",
"/*Browse.aspx*",
"/*browse.aspx*",
"/*browsexml.aspx*",
"/*BrowseXML.aspx*",
"/ssw/Redirect",
"/ssw/CodeAuditor",
"/ssw/Version.aspx",
"/ssw/LinkAuditor",
],
},
],
additionalSitemaps: [
"https://www.ssw.com.au/people/sitemap-index.xml",
"https://www.ssw.com.au/rules/sitemap-index.xml",
"https://www.ssw.com.au/archive/sitemap-index.xml",
// Removed v1 sitemap as its a duplication of bunch of Next.js pages - coming from
// "https://www.ssw.com.au/ssw/sitemap.xml",
// "https://www.ssw.com.au/history/sitemap.xml",
],
},
};