-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatic-sitemap.js
85 lines (76 loc) · 1.58 KB
/
static-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
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
const path = require("path");
const fs = require("fs");
const { ROUTES, BASE_URL } = require("./constants");
const allStaticPaths = [
{
loc: ROUTES.ROOT_ROUTE,
changefreq: "weekly",
priority: 1.0
},
{
loc: ROUTES.REFERRAL_ROUTE,
changefreq: "monthly",
priority: 0.8
},
{
loc: ROUTES.DOWNLOAD_ROUTE,
changefreq: "monthly",
priority: 0.7
},
{
loc: ROUTES.HOW_TO_PLAY_ROUTE,
changefreq: "monthly",
priority: 0.5
},
{
loc: ROUTES.LOGIN_ROUTE,
changefreq: "monthly",
priority: 0.8
},
{
loc: ROUTES.PRIVACY_ROUTE,
changefreq: "monthly",
priority: 0.5
},
{
loc: ROUTES.PROFILE_ROUTE,
changefreq: "monthly",
priority: 0.8
},
{
loc: ROUTES.RULES_ROUTE,
changefreq: "monthly",
priority: 0.5
},
{
loc: ROUTES.TERMS_ROUTE,
changefreq: "monthly",
priority: 0.5
}
];
let sitemapContents = "";
let timeLastMod = new Date().toISOString();
allStaticPaths.forEach(path => {
sitemapContents += `
<url>
<loc>${BASE_URL}${path.loc}</loc>
<lastmod>${timeLastMod}</lastmod>
<changefreq>${path.changefreq}</changefreq>
<priority>${path.priority}</priority>
</url>`;
});
sitemapContents = `<?xml version="1.0" encoding="utf-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">${sitemapContents}
</urlset>`;
let sitemapDir = "./sitemaps/";
let fileName = "static-sitemap.xml";
let outputFile = path.resolve(sitemapDir, fileName);
if (!fs.existsSync(sitemapDir)) {
fs.mkdirSync(sitemapDir);
}
fs.writeFile(outputFile, sitemapContents, err => {
if (err) {
console.log(err);
}
console.log(`The file ${outputFile} was created!`);
});