brackt/scripts/generate-sitemap.mjs

41 lines
1.3 KiB
JavaScript
Raw Permalink Normal View History

import { gzipSync } from "zlib";
import { writeFileSync } from "fs";
import { join, dirname } from "path";
import { fileURLToPath } from "url";
const __dirname = dirname(fileURLToPath(import.meta.url));
const publicDir = join(__dirname, "..", "public");
const BASE_URL = "https://brackt.com";
const urls = [
{ loc: "/", changefreq: "weekly", priority: "1.0" },
{ loc: "/how-to-play", changefreq: "monthly", priority: "0.8" },
{ loc: "/rules", changefreq: "monthly", priority: "0.8" },
{ loc: "/sports", changefreq: "weekly", priority: "0.8" },
{ loc: "/support", changefreq: "monthly", priority: "0.6" },
{ loc: "/privacy-policy", changefreq: "yearly", priority: "0.4" },
];
const today = new Date().toISOString().split("T")[0];
const xml = `<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
${urls
.map(
({ loc, changefreq, priority }) => ` <url>
<loc>${BASE_URL}${loc}</loc>
<lastmod>${today}</lastmod>
<changefreq>${changefreq}</changefreq>
<priority>${priority}</priority>
</url>`
)
.join("\n")}
</urlset>
`;
writeFileSync(join(publicDir, "sitemap.xml"), xml);
writeFileSync(join(publicDir, "sitemap.xml.gz"), gzipSync(xml));
console.log(`Sitemap generated: ${urls.length} URLs`);