-
-
Notifications
You must be signed in to change notification settings - Fork 863
/
sitemap.mjs
65 lines (58 loc) · 1.53 KB
/
sitemap.mjs
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
import path from 'node:path';
import fs from 'node:fs/promises';
async function getRoadmapIds() {
return fs.readdir(path.join(process.cwd(), 'src/data/roadmaps'));
}
async function getBestPracticesIds() {
return fs.readdir(path.join(process.cwd(), 'src/data/best-practices'));
}
export function shouldIndexPage(pageUrl) {
return ![
'https://roadmap.sh/404',
'https://roadmap.sh/terms',
'https://roadmap.sh/privacy',
'https://roadmap.sh/pdfs',
'https://roadmap.sh/g',
].includes(pageUrl);
}
export async function serializeSitemap(item) {
const highPriorityPages = [
'https://roadmap.sh',
'https://roadmap.sh/about',
'https://roadmap.sh/roadmaps',
'https://roadmap.sh/best-practices',
'https://roadmap.sh/guides',
'https://roadmap.sh/videos',
...(await getRoadmapIds()).flatMap((id) => [
`https://roadmap.sh/${id}`,
`https://roadmap.sh/${id}/topics`,
]),
...(await getBestPracticesIds()).map(
(id) => `https://roadmap.sh/best-practices/${id}`
),
];
// Roadmaps and other high priority pages
for (let pageUrl of highPriorityPages) {
if (item.url === pageUrl) {
return {
...item,
// @ts-ignore
changefreq: 'monthly',
priority: 1,
};
}
}
// Guide and video pages
if (
item.url.startsWith('https://roadmap.sh/guides') ||
item.url.startsWith('https://roadmap.sh/videos')
) {
return {
...item,
// @ts-ignore
changefreq: 'monthly',
priority: 0.9,
};
}
return undefined;
}