Skip to content

Commit 02fa2a0

Browse files
jaysin586claude
andcommitted
build: add sitemap:manifest script for cloudflare-deploy workflow
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent fa409da commit 02fa2a0

2 files changed

Lines changed: 48 additions & 3 deletions

File tree

docs/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"dev": "vite dev",
1212
"format": "prettier --write .",
1313
"lint": "prettier --check . && eslint .",
14-
"preview": "vite preview"
14+
"preview": "vite preview",
15+
"sitemap:manifest": "node ./scripts/generate-sitemap-manifest.mjs"
1516
},
1617
"dependencies": {
1718
"@humanspeak/svelte-markdown": "^1.4.1",
@@ -26,12 +27,12 @@
2627
"prettier": "^3.8.2",
2728
"prettier-plugin-svelte": "^3.5.1",
2829
"prettier-plugin-tailwindcss": "^0.7.2",
29-
"svelte": "^5.55.3",
30+
"svelte": "^5.55.4",
3031
"svelte-check": "^4.4.6",
3132
"tailwindcss": "^4.2.2",
3233
"typescript": "^6.0.2",
3334
"vite": "^8.0.8",
34-
"wrangler": "^4.81.1"
35+
"wrangler": "^4.82.2"
3536
},
3637
"volta": {
3738
"node": "24.13.0"
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { readdir, stat, writeFile } from 'node:fs/promises'
2+
import { join, resolve as resolvePath } from 'node:path'
3+
4+
const ROOT = resolvePath(process.cwd(), 'src', 'routes')
5+
6+
/** Convert a +page file path to a route path */
7+
function toRoutePath(file) {
8+
let p = file.replace(ROOT, '')
9+
p = p.replace(/\/\+page\.(svelte|svx|md)$/i, '')
10+
return p === '' ? '/' : p
11+
}
12+
13+
/** Recursively find +page files */
14+
async function findPageFiles(dir, out = []) {
15+
const entries = await readdir(dir, { withFileTypes: true })
16+
for (const e of entries) {
17+
const full = join(dir, e.name)
18+
if (e.isDirectory()) {
19+
await findPageFiles(full, out)
20+
} else if (/\+page\.(svelte|svx|md)$/i.test(e.name)) {
21+
out.push(full)
22+
}
23+
}
24+
return out
25+
}
26+
27+
async function main() {
28+
const files = await findPageFiles(ROOT)
29+
const manifest = {}
30+
for (const file of files) {
31+
const s = await stat(file)
32+
const route = toRoutePath(file)
33+
manifest[route] = new Date(s.mtimeMs).toISOString().slice(0, 10)
34+
}
35+
36+
const dest = resolvePath(process.cwd(), 'src', 'lib', 'sitemap-manifest.json')
37+
await writeFile(dest, JSON.stringify(manifest, null, 2) + '\n', 'utf8')
38+
console.log(`Sitemap manifest written to ${dest}`)
39+
}
40+
41+
main().catch((err) => {
42+
console.error(err)
43+
process.exit(1)
44+
})

0 commit comments

Comments
 (0)