forked from solidjs/solid-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerateSitemap.js
More file actions
26 lines (24 loc) · 834 Bytes
/
generateSitemap.js
File metadata and controls
26 lines (24 loc) · 834 Bytes
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
import { SitemapStream, streamToPromise } from "sitemap";
import { Readable } from "stream";
import entries from "../.solid/entriesList.js";
import fs from "fs";
const generateLinkArray = (routes) => {
return routes.reduce((acc, route) => {
return [
...acc,
{ url: route, priority: route == "/" ? 1 : 0.7, changefreq: "weekly" },
];
}, []);
};
(async () => {
const referencesRoutes = entries.reference.map(({ path }) => path);
const learnRoutes = entries.learn.map(({ path }) => path);
const links = [
...generateLinkArray(learnRoutes),
...generateLinkArray(referencesRoutes),
];
const stream = new SitemapStream({ hostname: "https://docs.solidjs.com/" });
return streamToPromise(Readable.from(links).pipe(stream)).then((data) =>
fs.writeFileSync("public/sitemap.xml", data, { encoding: "utf-8" })
);
})();