Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions generate-sitemap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const { SitemapStream, streamToPromise } = require("sitemap");
const { createWriteStream } = require("fs");
const path = require("path");

// Define the base URL of the website
const BASE_URL = "https://admin.bashaway.sliitfoss.org";

// Define the public routes with their change frequency and priority
const routes = [
{ url: "/", changefreq: "daily", priority: 1.0 },
{ url: "/dashboard", changefreq: "daily", priority: 0.9 },
{ url: "/events", changefreq: "weekly", priority: 0.8 },
{ url: "/users", changefreq: "weekly", priority: 0.8 },
{ url: "/login", changefreq: "monthly", priority: 0.7 },
{ url: "/questions", changefreq: "weekly", priority: 0.8 },
{ url: "/questions/1", changefreq: "weekly", priority: 0.6 }, // Example dynamic route
{ url: "/questions/2", changefreq: "weekly", priority: 0.6 }, // Example dynamic route
{ url: "/questions/1/submissions", changefreq: "weekly", priority: 0.5 }, // Example dynamic route
{ url: "/forgot-password", changefreq: "yearly", priority: 0.3 },
{ url: "/reset-password/example-code", changefreq: "yearly", priority: 0.3 }, // Example dynamic route
{ url: "/change-password", changefreq: "yearly", priority: 0.4 },
{ url: "/profile", changefreq: "monthly", priority: 0.6 }
];

(async () => {
try {
// Create a sitemap stream
const sitemapStream = new SitemapStream({ hostname: BASE_URL });

// Write each route to the sitemap stream
routes.forEach((route) => sitemapStream.write(route));

// End the stream
sitemapStream.end();

// Convert the stream to a promise and save it to a file
const sitemapPath = path.join(__dirname, "public", "sitemap.xml");
const writeStream = createWriteStream(sitemapPath);
const sitemap = await streamToPromise(sitemapStream).then((data) => data.toString());

writeStream.write(sitemap);
writeStream.end();

console.log("Sitemap successfully generated at:", sitemapPath);
} catch (error) {
console.error("Error generating sitemap:", error);
}
})();
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"lefthook": "1.4.3",
"postcss": "8.4.23",
"prettier": "2.8.8",
"sitemap": "8.0.0",
"tailwindcss": "3.3.2",
"tailwindcss-animate": "1.0.6",
"vite": "4.3.9"
Expand Down
Loading