start work on table of contents

This commit is contained in:
2023-08-20 22:04:21 -07:00
parent b1dc3ae0ea
commit 33d6838dc4
4 changed files with 90 additions and 1 deletions

View File

@ -4,7 +4,7 @@ import { toText } from 'hast-util-to-text';
import { makeSlug } from '../lib/utils.js';
export function localPlugins() {
export function localRehype() {
let printed = false;
return (tree, vfile) => {

19
src/plugins/remark.js Normal file
View File

@ -0,0 +1,19 @@
import { visit } from 'unist-util-visit';
import { toString } from 'mdast-util-to-string';
// build table of contents and inject into frontmatter
export function localRemark() {
return (tree, vfile) => {
let toc = [];
visit(tree, 'heading', node => {
toc.push({
text: toString(node),
depth: node.depth,
});
});
vfile.data.fm.toc = toc;
}
}