arredemo
Version:
Instantly build a static site for your package
26 lines (19 loc) • 553 B
JavaScript
import { slugify, stripHtml } from "app/util/text.mjs"
const parseMenu = (contentNode) => {
const headings= contentNode.querySelectorAll('h1, h2, h3')
const parseHead = (h) => {
const level= parseInt(h.tagName.replace('H', ''))
const title= stripHtml(h.innerHTML.trim())
const slug= slugify(title)
return {
title,
id: slug,
level,
//node: h
}
}
const menu= Array.prototype.map.call(headings, h => parseHead(h))
.filter(m => m!=undefined)
return menu
}
export default parseMenu