-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatches-sitemap.js
47 lines (39 loc) · 1.38 KB
/
matches-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
const path = require("path");
const fs = require("fs");
const { getAllSports, getAllMatches } = require("./requests");
(async () => {
const allSportPaths = await getAllSports();
allSportPaths.forEach(async sport => {
if ((sport.sportName || "").toLowerCase() !== "quiz") {
const matchesData = await getAllMatches(sport.sportId);
let sitemapContents = "";
let timeLastMod = new Date().toISOString();
if (matchesData.length > 0) {
matchesData.forEach(path => {
sitemapContents += `
<url>
<loc>${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 = `${sport.sportName}-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!`);
});
}
}
});
})();