feat: provide sitemap

closes #287
This commit is contained in:
Danny Koppenhagen
2023-01-07 15:21:53 +01:00
committed by Bastian
parent 9a8bb235a4
commit caff3640a2
5 changed files with 271 additions and 5 deletions

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env node
import { copyFileSync, existsSync, mkdirSync, readFileSync } from "fs";
import { copyFileSync, mkdirSync, existsSync, readFileSync, writeFileSync } from "fs";
import XmlSitemap from "xml-sitemap";
import { createRadar } from "./generateJson/radar";
// Do this as the first thing so that any code reading it knows the right env.
@@ -22,6 +22,7 @@ const createStaticFiles = async () => {
copyFileSync("build/index.html", "build/help-and-about-tech-radar.html");
const rawConf = readFileSync("build/config.json", "utf-8");
const config = JSON.parse(rawConf);
Object.keys(config.quadrants).forEach((quadrant) => {
const destFolder = `build/${quadrant}`;
copyFileSync("build/index.html", `${destFolder}.html`);
@@ -29,12 +30,22 @@ const createStaticFiles = async () => {
mkdirSync(destFolder);
}
});
const sitemap = new XmlSitemap();
radar.items.forEach((item) => {
copyFileSync(
"build/index.html",
`build/${item.quadrant}/${item.name}.html`
);
sitemap.add(`${process.env.PUBLIC_URL}/${item.quadrant}/${item.name}.html`, {
lastmod: 'now',
changefreq: 'weekly'
});
});
writeFileSync("build/sitemap.xml", sitemap.xml);
};
createStaticFiles()