-
Notifications
You must be signed in to change notification settings - Fork 52
/
sitemap.config.js
58 lines (50 loc) · 1.36 KB
/
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
/** @type {import('next-sitemap').IConfig} */
module.exports = {
siteUrl: "https://www.comflowy.com",
generateRobotsTxt: true,
changefreq: "weekly",
transform: async (config, path) => {
path = modifyUrl(path);
// Use default transformation for all other cases
return {
loc: path, // => this will be exported as http(s)://<config.siteUrl>/<path>
changefreq: config.changefreq,
priority: getURLPriority(path),
lastmod: config.autoLastmod ? new Date().toISOString() : undefined,
alternateRefs: config.alternateRefs ?? [],
}
},
additionalPaths: async (config) => {
const result = [];
result.push({
loc: '/',
priority: 1.0
})
return result;
}
}
function modifyUrl(url) {
// Check if the URL ends with .zh-CN
if (/.zh-CN$/.test(url)) {
url = url.replace(/(.*).zh-CN$/, 'zh-CN$1');
}
// Check if the URL ends with .en-US
else if (/.en-US$/.test(url)) {
url = url.replace(/(.*)\/(.*).en-US$/, '$1/$2');
}
if (/index$/.test(url)) {
url = url.replace(/(.*)\/index$/, '$1');
}
// If the URL doesn't match any of the above conditions, return it as is
return url;
}
function getURLPriority(url) {
console.log(url);
if (url === "zh-CN" || url.trim() === "") {
return 1.0
}
if (/blog$/.test(url)) {
return 0.6
}
return 0.7
}