MCPcopy Create free account
hub / github.com/frank-lam/fullstack-tutorial / genIndex

Function genIndex

notes/docsify/unpkg/docsify/lib/plugins/search.js:42–69  ·  view source on GitHub ↗
(path, content, router, depth)

Source from the content-addressed store, hash-verified

40}
41
42function genIndex(path, content, router, depth) {
43 if ( content === void 0 ) content = '';
44
45 var tokens = window.marked.lexer(content);
46 var slugify = window.Docsify.slugify;
47 var index = {};
48 var slug;
49
50 tokens.forEach(function (token) {
51 if (token.type === 'heading' && token.depth <= depth) {
52 slug = router.toURL(path, {id: slugify(token.text)});
53 index[slug] = {slug: slug, title: token.text, body: ''};
54 } else {
55 if (!slug) {
56 return
57 }
58 if (!index[slug]) {
59 index[slug] = {slug: slug, title: '', body: ''};
60 } else if (index[slug].body) {
61 index[slug].body += '\n' + (token.text || '');
62 } else {
63 index[slug].body = token.text;
64 }
65 }
66 });
67 slugify.clear();
68 return index
69}
70
71/**
72 * @param {String} query

Callers 1

init$1Function · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected