43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
import { createWriteStream } from "fs";
|
|
import { SitemapStream, streamToPromise } from "sitemap";
|
|
|
|
// Base URL of your website
|
|
const baseUrl = "https://monde-usage.vercel.app";
|
|
const routes = [
|
|
{ url: "/", changefreq: "monthly", priority: 0.5 }, // Homepage
|
|
{ url: "/about", changefreq: "monthly", priority: 0.9 }, // Higher priority
|
|
{ url: "/contact", changefreq: "monthly", priority: 0.9 }, // Higher priority
|
|
{ url: "/le-film-des-legumes", changefreq: "monthly", priority: 0.8 },
|
|
{ url: "/le-monde-en-carton", changefreq: "monthly", priority: 0.8 },
|
|
];
|
|
|
|
// Create a sitemap
|
|
const generateSitemap = async () => {
|
|
try {
|
|
// Create a stream to write the sitemap to a file
|
|
const sitemapStream = new SitemapStream({ hostname: baseUrl });
|
|
const writeStream = createWriteStream("./public/sitemap.xml");
|
|
|
|
// Pipe the stream to the file
|
|
sitemapStream.pipe(writeStream);
|
|
|
|
// Add each route to the sitemap with their specific attributes
|
|
routes.forEach((route) => {
|
|
sitemapStream.write(route);
|
|
});
|
|
|
|
// End the sitemap stream
|
|
sitemapStream.end();
|
|
|
|
// Wait for the stream to finish
|
|
await streamToPromise(sitemapStream);
|
|
|
|
console.log("Sitemap generated successfully!");
|
|
} catch (error) {
|
|
console.error("Error generating sitemap:", error);
|
|
}
|
|
};
|
|
|
|
// Run the sitemap generation function
|
|
generateSitemap();
|