-
Notifications
You must be signed in to change notification settings - Fork 1
/
sitemap.cjs
44 lines (37 loc) · 1.03 KB
/
sitemap.cjs
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
const { SitemapStream, streamToPromise } = require("sitemap");
const { createReadStream, createWriteStream } = require("fs");
const { Readable } = require("stream");
const { StaticRouter } = require("react-router-dom");
const React = require("react");
const ReactDOMServer = require("react-dom/server");
const renderToString = (element) =>
ReactDOMServer.renderToString(React.createElement(element));
async function generateSitemap() {
const staticRoutes = [
"/",
"about",
"guidelines",
"events",
"/set1",
"/set2",
"/judges",
];
const smStream = new SitemapStream({
hostname: "https://hackatank.shadowctrl.me",
});
staticRoutes.forEach((route) => {
smStream.write({
url: route,
changefreq: "yearly",
priority: 1,
});
});
smStream.end();
const sitemapXml = await streamToPromise(Readable.from(smStream), {
encoding: "utf-8",
});
const writeStream = createWriteStream("./public/sitemap.xml");
writeStream.write(sitemapXml);
writeStream.end();
}
generateSitemap();