-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathcreate-sitemap.ts
42 lines (32 loc) · 1.09 KB
/
create-sitemap.ts
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
import { sitemapBuilder as buildSitemap } from "react-router-sitemap";
var fs = require("fs");
const regex = /pages: (\[[\w\W]+?\])/gm;
let source = regex.exec(fs.readFileSync("./apps/official/index.ts").toString())[1];
//console.log(source);
let ignorePaths = ["questions"];
let pathPrefix = "/#/";
var paths = source
.split(",")
.map((x) => x.split(":").map((y) => y.trim()))
.reduce((a, x) => {
if (x[0] == "route") {
let route = x[1].replace(/["'/]/g, "");
if (ignorePaths.findIndex((p) => route === p) == -1) {
a.push(pathPrefix + route);
}
}
return a;
}, []);
const hostname = "https://www.covmap.de";
const sitemap = buildSitemap(hostname, paths);
console.log(sitemap);
const { createWriteStream } = require("fs");
const { SitemapStream } = require("sitemap");
// Creates a sitemap object given the input configuration with URLs
const sitemapSteam = new SitemapStream(sitemap);
const writeStream = createWriteStream("./static/sitemap.xml");
sitemapSteam.pipe(writeStream);
paths.forEach((path) => {
sitemapSteam.write(path);
});
sitemapSteam.end();