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

Contents of /branches/8.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: 1682 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 .replace(/\\/g, '/');
16
17 route =
18 route === "" || route === "page.tsx" || route === "page.mdx"
19 ? "/"
20 : `/${route}`;
21
22 if (excluded.includes(route)) {
23 continue;
24 }
25
26 const lastmod = lstatSync(page).mtime;
27
28 routes.push({
29 path: route,
30 file: page.replace(/\\/g, '/'),
31 lastmod,
32 });
33 }
34
35 const urls = routes.map(
36 route =>
37 "\t" +
38 `
39 <url>
40 <loc>${route.path}</loc>
41 <lastmod>${route.lastmod.toISOString()}</lastmod>
42 <priority>${route.path === "/" ? "1.0" : "0.8"}</priority>
43 </url>`.trim(),
44 );
45
46 const urlset = `
47 <?xml version="1.0" encoding="UTF-8"?>
48 <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
49 ${urls.join("\n")}
50 </urlset>
51 `.trim();
52
53 const json = JSON.stringify(
54 routes.map(route => ({
55 loc: route.path,
56 lastmod: route.lastmod.toISOString(),
57 priority: route.path === "/" ? 1.0 : 0.8,
58 })),
59 );
60
61 writeFileSync(path.join(__dirname, "sitemap.xml"), urlset);
62 writeFileSync(path.join(__dirname, "sitemap.json"), json);
63 }
64
65 main();

team@onesoftnet.eu.org
ViewVC Help
Powered by ViewVC 1.1.26