start work on table of contents
This commit is contained in:
@ -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
19
src/plugins/remark.js
Normal 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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user