Files
react-website/scripts/generate-sitemap.mjs
T
MehboobKandClaude Sonnet 5 3a209bd79a
CI / build (push) Canceled after 0s
Add ROI Calculator page, polish Mobile SDK explorer tabs and hero layout
Wires a new /roi-calculator route into nav, routing, sitemap and SEO
metadata, and enlarges the Mobile SDK explorer's tab tiles and phone
stage for better readability.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-13 16:17:24 +05:00

48 lines
2.0 KiB
JavaScript

/**
* Writes public/sitemap.xml and public/robots.txt from the content that will ship
* in the build. The server also serves a live sitemap at /sitemap.xml (which picks
* up articles published after the build); this static copy is the fallback for
* static hosting and for crawlers hitting the file directly.
*
* node scripts/generate-sitemap.mjs [siteUrl]
*/
import fs from 'node:fs'
import path from 'node:path'
const ROOT = path.resolve(import.meta.dirname, '..')
const SITE_URL = (process.argv[2] || process.env.SITE_URL || 'https://www.blackdice.ai').replace(/\/+$/, '')
const PATHS = [
['/', '1.0'], ['/mobile-sdk', '0.9'], ['/dns-protect', '0.9'], ['/halo-cpe', '0.9'],
['/for-operators', '0.8'], ['/roi-calculator', '0.7'], ['/financial-services', '0.8'], ['/why-blackdice', '0.7'],
['/news', '0.8'], ['/investors', '0.6'], ['/contact', '0.7'],
]
const seed = JSON.parse(fs.readFileSync(path.join(ROOT, 'src/cms/generated/seedContent.json'), 'utf8'))
const live = (() => {
const file = path.join(ROOT, 'content/site-content.json')
return fs.existsSync(file) ? JSON.parse(fs.readFileSync(file, 'utf8')) : null
})()
const posts = (live?.posts || seed.posts || []).filter((p) => p.status !== 'draft')
const today = new Date().toISOString().slice(0, 10)
const urls = [
...PATHS.map(([p, pri]) => ({ loc: SITE_URL + p, lastmod: today, pri })),
...posts.map((p) => ({
loc: `${SITE_URL}/blog/${p.slug}`,
lastmod: (p.updatedAt || p.date || today).slice(0, 10),
pri: '0.6',
})),
]
const xml =
'<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n' +
urls
.map((u) => ` <url>\n <loc>${u.loc}</loc>\n <lastmod>${u.lastmod}</lastmod>\n <priority>${u.pri}</priority>\n </url>`)
.join('\n') +
'\n</urlset>\n'
fs.writeFileSync(path.join(ROOT, 'public/sitemap.xml'), xml)
fs.writeFileSync(path.join(ROOT, 'public/robots.txt'), `User-agent: *\nAllow: /\n\nSitemap: ${SITE_URL}/sitemap.xml\n`)
console.log(`sitemap.xml: ${urls.length} URLs (${posts.length} articles) → ${SITE_URL}`)