/[sudobot]/branches/7.x/docs/generate-sitemap.js
ViewVC logotype

Contents of /branches/7.x/docs/generate-sitemap.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 577 - (show annotations)
Mon Jul 29 18:52:37 2024 UTC (8 months ago) by rakinar2
File MIME type: text/javascript
File size: 1608 byte(s)
chore: add old version archive branches (2.x to 9.x-dev)
1 const { glob } = require("glob");
2 const { writeFileSync, lstatSync } = require("fs");
3 const path = require("path");
4
5 async function main() {
6 const excluded = [];
7 const pages = await glob("app/**/page.{ts,md}x");
8 const routes = [];
9
10 for (const page of pages) {
11 let route = page
12 .replace(/\/\([a-z0-9A-Z_-]+\)/gi, "")
13 .replace(/^app\//gi, "")
14 .replace(/\/page\.(ts|md)x/gi, "");
15 route =
16 route === "" || route === "page.tsx" || route === "page.mdx"
17 ? "/"
18 : `/${route}`;
19
20 if (excluded.includes(route)) {
21 continue;
22 }
23
24 const lastmod = lstatSync(page).mtime;
25
26 routes.push({
27 path: route,
28 file: page,
29 lastmod,
30 });
31 }
32
33 const urls = routes.map(
34 route =>
35 "\t" +
36 `
37 <url>
38 <loc>${route.path}</loc>
39 <lastmod>${route.lastmod.toISOString()}</lastmod>
40 <priority>${route.path === "/" ? "1.0" : "0.8"}</priority>
41 </url>`.trim(),
42 );
43
44 const urlset = `
45 <?xml version="1.0" encoding="UTF-8"?>
46 <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
47 ${urls.join("\n")}
48 </urlset>
49 `.trim();
50
51 const json = JSON.stringify(
52 routes.map(route => ({
53 loc: route.path,
54 lastmod: route.lastmod.toISOString(),
55 priority: route.path === "/" ? 1.0 : 0.8,
56 })),
57 );
58
59 writeFileSync(path.join(__dirname, "sitemap.xml"), urlset);
60 writeFileSync(path.join(__dirname, "sitemap.json"), json);
61 }
62
63 main();

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26