Refactor site generation into a modular content pipeline
Deploy website / deploy (push) Successful in 24s

This commit is contained in:
paul committed 2026-09-22 20:51:13 -04:00
1 parent 0f69028d4a
commit 146d516f24
20 files changed
+826 -427

No files matched your search

+31
View File
@@ -0,0 +1,31 @@
import { parse } from 'parse5'
const attribute = (node, name) => node.attrs?.find((item) => item.name === name)?.value
export const htmlFacts = (html) => {
const facts = {
ids: [], hrefs: [], languages: [],
hasViewport: false, hasHeadingElement: false, isDraft: false,
}
const visit = (node) => {
if (node.tagName) {
const id = attribute(node, 'id')
if (id !== undefined) facts.ids.push(id)
const href = attribute(node, 'href')
if (href !== undefined) facts.hrefs.push(href)
for (const className of (attribute(node, 'class') ?? '').split(/\s+/)) {
if (className.startsWith('language-')) facts.languages.push(className.slice('language-'.length))
}
if (node.tagName === 'heading') facts.hasHeadingElement = true
if (node.tagName === 'meta') {
const name = attribute(node, 'name')?.toLowerCase()
if (name === 'viewport') facts.hasViewport = true
if (name === 'robots' && /(?:^|[,\s])noindex(?:$|[,\s])/i.test(attribute(node, 'content') ?? '')) facts.isDraft = true
}
}
for (const child of node.childNodes ?? []) visit(child)
if (node.content) visit(node.content)
}
visit(parse(html))
return facts
}