MCPcopy
hub / github.com/docsifyjs/docsify / genIndex

Function genIndex

src/plugins/search/search.js:82–137  ·  view source on GitHub ↗
(path, content = '', router, depth)

Source from the content-addressed store, hash-verified

80}
81
82export function genIndex(path, content = '', router, depth) {
83 const tokens = window.marked.lexer(content);
84 const slugify = window.Docsify.slugify;
85 const index = {};
86 let slug;
87 let title = '';
88
89 tokens.forEach(function (token, tokenIndex) {
90 if (token.type === 'heading' && token.depth <= depth) {
91 const { str, config } = getAndRemoveConfig(token.text);
92
93 const text = removeDocsifyIgnoreTag(token.text);
94
95 if (config.id) {
96 slug = router.toURL(path, { id: slugify(config.id) });
97 } else {
98 slug = router.toURL(path, { id: slugify(escapeHtml(text)) });
99 }
100
101 if (str) {
102 title = removeDocsifyIgnoreTag(str);
103 }
104
105 index[slug] = { slug, title: title, body: '' };
106 } else {
107 if (tokenIndex === 0) {
108 slug = router.toURL(path);
109 index[slug] = {
110 slug,
111 title: path !== '/' ? path.slice(1) : 'Home Page',
112 body: token.text || '',
113 };
114 }
115
116 if (!slug) {
117 return;
118 }
119
120 if (!index[slug]) {
121 index[slug] = { slug, title: '', body: '' };
122 } else if (index[slug].body) {
123 token.text = getTableData(token);
124 token.text = getListData(token);
125
126 index[slug].body += '\n' + (token.text || '');
127 } else {
128 token.text = getTableData(token);
129 token.text = getListData(token);
130
131 index[slug].body = token.text || '';
132 }
133 }
134 });
135 slugify.clear();
136 return index;
137}
138
139export function ignoreDiacriticalMarks(keyword) {

Callers 1

initFunction · 0.85

Calls 7

getAndRemoveConfigFunction · 0.90
removeDocsifyIgnoreTagFunction · 0.90
slugifyFunction · 0.85
escapeHtmlFunction · 0.85
getTableDataFunction · 0.85
getListDataFunction · 0.85
toURLMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…