24 lines
984 B
JavaScript
24 lines
984 B
JavaScript
import { readFile, writeFile } from 'node:fs/promises'
|
|
import path from 'node:path'
|
|
import { fileURLToPath } from 'node:url'
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
const registryPath = path.join(__dirname, '..', 'src', 'public-route-registry.json')
|
|
const sitemapPath = path.join(__dirname, '..', 'public', 'sitemap.xml')
|
|
const baseUrl = 'https://hypertwist.app'
|
|
|
|
const routeRegistry = JSON.parse(await readFile(registryPath, 'utf8'))
|
|
const crawlableRoutes = routeRegistry.filter((route) => route && route.crawlable === true)
|
|
|
|
const xml = [
|
|
'<?xml version="1.0" encoding="UTF-8"?>',
|
|
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">',
|
|
...crawlableRoutes.map((route) => (
|
|
` <url>\n <loc>${baseUrl}${route.path === '/' ? '/' : route.path}</loc>\n </url>`
|
|
)),
|
|
'</urlset>',
|
|
'',
|
|
].join('\n')
|
|
|
|
await writeFile(sitemapPath, xml, 'utf8')
|
|
console.log(`Rendered sitemap for ${crawlableRoutes.length} crawlable routes to ${sitemapPath}`)
|