-
Notifications
You must be signed in to change notification settings - Fork 41
/
sitemap.js
40 lines (37 loc) · 1.08 KB
/
sitemap.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
const fs = require("fs");
const jsonDB = JSON.parse(fs.readFileSync("./src/assert/db.json", "utf-8"));
const linkPrefix = "https://urarawin.com";
const sitemaps = [
"/",
"/support",
"/skill",
"/nurturing",
"/nurturingMo",
"/seed",
"/SeedMo",
"/race",
// "/player-detail/:id",
// "/support-detail/:id",
// "/skill-detail/:id",
"/buff",
];
for (let player of jsonDB.players) {
sitemaps.push(`/player-detail/${player.id}`);
}
for (let support of jsonDB.supports) {
sitemaps.push(`/support-detail/${support.id}`);
}
for (let skill of jsonDB.skills) {
sitemaps.push(`/skill-detail/${skill.id}`);
}
const initSiteMap = async () => {
const sitemap = sitemaps.map((e) => linkPrefix + e).join("\n");
console.log(`Sitemap: ${linkPrefix}/sitemap.txt`);
fs.writeFileSync(`./public/sitemap.txt`, sitemap);
// 判断robots里是否有对应的sitemap
const robots = fs.readFileSync("./public/robots.txt", "utf8");
if (!robots.includes(`${linkPrefix}/sitemap.txt`)) {
fs.appendFileSync("./public/robots.txt", `Sitemap: ${linkPrefix}/sitemap.txt\n`);
}
};
initSiteMap();