| 40 | } |
| 41 | |
| 42 | function 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 |