-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsite-map-gen.js
41 lines (32 loc) · 1.03 KB
/
site-map-gen.js
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
import { writeFile } from "fs/promises";
import { SitemapStream, streamToPromise } from "sitemap";
import { fileURLToPath } from "url";
import path from "path";
// Define your base URL
const baseUrl = "https://abhisarga-iiits.in";
// Define your website's important routes
const pages = [
"/",
"/about",
"/events",
"/schedule",
"/merch",
"/call-for-sponsors",
"/sponsors",
"/contact",
"/accommodation"
];
// Get the current directory equivalent to __dirname
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
(async () => {
const sitemap = new SitemapStream({ hostname: baseUrl });
pages.forEach((page) => {
sitemap.write({ url: page, changefreq: "daily", priority: 0.8 });
});
sitemap.end();
const sitemapXML = await streamToPromise(sitemap);
// Save the sitemap.xml inside the 'public' folder
await writeFile(path.join(__dirname, "public", "sitemap.xml"), sitemapXML);
console.log("✅ Sitemap successfully generated in the 'public/' folder!");
})();