-
-
Notifications
You must be signed in to change notification settings - Fork 104
/
sitemap.js
45 lines (44 loc) · 1.32 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
41
42
43
44
45
//read from process.env.PUBLIC_KENER_FOLDER / site.json
//read from process.env.PUBLIC_KENER_FOLDER / monitors.json
// create sitemap.xml
import fs from "fs-extra";
let siteMap = "";
import dotenv from "dotenv";
dotenv.config();
const site = fs.readJSONSync("./database/site.json", "utf8");
const monitors = fs.readJSONSync("./database/monitors.json", "utf8");
if (site.siteURL !== undefined && site.siteURL !== null && site.siteURL !== "") {
if (monitors.length > 0) {
siteMap = `<?xml version="1.0" encoding="UTF-8"?>
<urlset
xmlns="https://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://www.sitemaps.org/schemas/sitemap/0.9
https://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
${monitors
.map((monitor) => {
return `
<url>
<loc>${site.siteURL}/incident/${monitor.folderName}</loc>
<lastmod>${new Date().toISOString()}</lastmod>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>`;
})
.join("\n")}
${monitors
.map((monitor) => {
return `
<url>
<loc>${site.siteURL}/monitor-${encodeURIComponent(monitor.tag)}</loc>
<lastmod>${new Date().toISOString()}</lastmod>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>`;
})
.join("\n")}
</urlset>`;
}
}
//export default siteMap
export default siteMap;