-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgenerate-sitemap.js
37 lines (32 loc) · 1.05 KB
/
generate-sitemap.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
import { SitemapStream, streamToPromise } from "sitemap";
import { createWriteStream } from "fs";
import { Readable } from "stream";
(async () => {
// Define the hostname for your sitemap
const hostname = "https://shadcnui-theme-editor.nadeemashraf.dev";
// Define your pages
const pages = [
{ url: "/", changefreq: "daily", priority: 1.0 },
// Add other pages here
];
// Create a readable stream for your pages
const stream = new Readable({
objectMode: true,
read() {
pages.forEach((page) => this.push(page));
this.push(null);
},
});
// Create a stream to write to the sitemap file
const sitemap = new SitemapStream({ hostname });
// Pipe the readable stream into the SitemapStream and then into a writable stream
try {
const data = await streamToPromise(stream.pipe(sitemap)).then((data) =>
data.toString()
);
createWriteStream("./public/sitemap.xml").write(data);
console.log("Sitemap successfully created!");
} catch (error) {
console.error("Error creating sitemap:", error);
}
})();