diff --git a/.gitignore b/.gitignore index 68ebecb..5f9cedf 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,7 @@ storybook-static # Clerk migration export — contains password hashes, never commit exported_users.csv + +# Generated at build time by scripts/generate-sitemap.mjs +/public/sitemap.xml +/public/sitemap.xml.gz diff --git a/package.json b/package.json index 00184e8..ef28a85 100644 --- a/package.json +++ b/package.json @@ -3,8 +3,9 @@ "private": true, "type": "module", "scripts": { - "build": "npm run build:remix && npm run build:server", + "build": "npm run sitemap && npm run build:remix && npm run build:server", "build:remix": "react-router build", + "sitemap": "node scripts/generate-sitemap.mjs", "build:server": "node scripts/build-server.mjs", "db:generate": "dotenv -- drizzle-kit generate", "db:migrate": "dotenv -- drizzle-kit migrate", diff --git a/public/robots.txt b/public/robots.txt new file mode 100644 index 0000000..aa7e420 --- /dev/null +++ b/public/robots.txt @@ -0,0 +1,11 @@ +User-agent: * +Allow: / + +Disallow: /admin/ +Disallow: /api/ +Disallow: /leagues/ +Disallow: /onboarding +Disallow: /settings +Disallow: /user-profile + +Sitemap: https://brackt.com/sitemap.xml diff --git a/scripts/generate-sitemap.mjs b/scripts/generate-sitemap.mjs new file mode 100644 index 0000000..b29bd12 --- /dev/null +++ b/scripts/generate-sitemap.mjs @@ -0,0 +1,40 @@ +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 = ` + +${urls + .map( + ({ loc, changefreq, priority }) => ` + ${BASE_URL}${loc} + ${today} + ${changefreq} + ${priority} + ` + ) + .join("\n")} + +`; + +writeFileSync(join(publicDir, "sitemap.xml"), xml); +writeFileSync(join(publicDir, "sitemap.xml.gz"), gzipSync(xml)); + +console.log(`Sitemap generated: ${urls.length} URLs`);