Skip to content

Commit 587115e

Browse files
committed
Add sitemap.xml
1 parent 3073512 commit 587115e

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

generate/index.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/**
22
* @import {Root} from 'hast'
33
* @import {DataMap} from 'vfile'
4+
* @import {Entry as SitemapEntry} from 'xast-util-sitemap'
45
* @import {Human} from '../data/humans.js'
56
* @import {Release} from '../data/releases.js'
67
* @import {Person as Sponsor} from '../data/sponsors.js'
@@ -32,6 +33,8 @@ import {read, write} from 'to-vfile'
3233
import {matter} from 'vfile-matter'
3334
import {reporter} from 'vfile-reporter'
3435
import {VFile} from 'vfile'
36+
import {sitemap} from 'xast-util-sitemap'
37+
import {toXml} from 'xast-util-to-xml'
3538
import yaml from 'yaml'
3639
import {humans} from '../data/humans.js'
3740
import {releases as dataReleases} from '../data/releases.js'
@@ -411,13 +414,29 @@ page(
411414
}
412415
)
413416

417+
/** @type {Array<SitemapEntry>} */
418+
const sitemapEntries = []
419+
414420
for (const render of tasks) {
415421
const {tree, file} = await render()
416422
file.value = pipeline.stringify(await pipeline.run(tree, file), file)
417423
await write(file)
418-
console.log(reporter(file))
424+
console.error(reporter(file))
425+
const meta = file.data.meta || {}
426+
const matter = file.data.matter || {}
427+
const pathname = matter.pathname || meta.pathname
428+
const modified = matter.modified || meta.modified
429+
assert(pathname)
430+
sitemapEntries.push({url: new URL(pathname, origin).href, modified})
419431
}
420432

433+
await fs.writeFile(
434+
new URL('../build/sitemap.xml', import.meta.url),
435+
toXml(sitemap(sitemapEntries))
436+
)
437+
438+
console.log('✔ `/sitemap.xml`')
439+
421440
/**
422441
*
423442
* @param {() => Root} render

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@
108108
"vfile-matter": "^5.0.0",
109109
"vfile-rename": "^3.0.0",
110110
"vfile-reporter": "^8.0.0",
111+
"xast-util-sitemap": "^2.0.0",
112+
"xast-util-to-xml": "^4.0.0",
111113
"xastscript": "^4.0.0",
112114
"xo": "^0.59.0",
113115
"yaml": "^2.0.0"

0 commit comments

Comments
 (0)