Joshua Bemenderfer 9d9757e868 Updates.
2025-09-08 16:24:38 -04:00

27 lines
589 B
JavaScript

import slugify from '@sindresorhus/slugify'
export default async function (doc, rootNode, context) {
const headingLevel = +rootNode.tail.split(' ')[0]
const text = rootNode.tail.split(' ').slice(1).join(' ')
const slug = slugify(text)
const node = {
type: rootNode.head,
level: headingLevel,
text,
slug,
class: '',
href: '',
children: []
}
for await (const child of rootNode.children()) {
if (child.is('class')) node.class = child.tail
if (child.is('href')) node.href = child.tail
}
context.page.headings.push(node)
return node
}