diff --git a/docs/de-de/plugins.md b/docs/de-de/plugins.md index f9ba36cc..e1fb43e4 100644 --- a/docs/de-de/plugins.md +++ b/docs/de-de/plugins.md @@ -35,7 +35,10 @@ Als Standardeinstellung werden Hyperlinks auf der aktuellen Seite erkannt und de noData: { '/de-de/': 'Keine Ergebnisse', '/': 'No Results' - } + }, + + // Headline depth, 1 - 6 + depth: 2 } } diff --git a/docs/plugins.md b/docs/plugins.md index 225a684f..1da76776 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -35,7 +35,10 @@ By default, the hyperlink on the current page is recognized and the content is s noData: { '/zh-cn/': '找不到结果', '/': 'No Results' - } + }, + + // Headline depth, 1 - 6 + depth: 2 } } diff --git a/docs/zh-cn/plugins.md b/docs/zh-cn/plugins.md index 6e19cd46..4d8829b6 100644 --- a/docs/zh-cn/plugins.md +++ b/docs/zh-cn/plugins.md @@ -35,7 +35,10 @@ noData: { '/zh-cn/': '找不到结果', '/': 'No Results' - } + }, + + // 搜索标题的最大程级, 1 - 6 + depth: 2 } } diff --git a/src/plugins/search/index.js b/src/plugins/search/index.js index db3ca575..66e5fba2 100644 --- a/src/plugins/search/index.js +++ b/src/plugins/search/index.js @@ -5,6 +5,7 @@ const CONFIG = { placeholder: 'Type to search', noData: 'No Results!', paths: 'auto', + depth: 2, maxAge: 86400000 // 1 day } @@ -19,6 +20,7 @@ const install = function (hook, vm) { CONFIG.maxAge = util.isPrimitive(opts.maxAge) ? opts.maxAge : CONFIG.maxAge CONFIG.placeholder = opts.placeholder || CONFIG.placeholder CONFIG.noData = opts.noData || CONFIG.noData + CONFIG.depth = opts.depth || CONFIG.depth } const isAuto = CONFIG.paths === 'auto' diff --git a/src/plugins/search/search.js b/src/plugins/search/search.js index e8cbb5b9..3615ea4b 100644 --- a/src/plugins/search/search.js +++ b/src/plugins/search/search.js @@ -38,14 +38,14 @@ function saveData (maxAge) { localStorage.setItem('docsify.search.index', JSON.stringify(INDEXS)) } -export function genIndex (path, content = '', router) { +export function genIndex (path, content = '', router, depth) { const tokens = window.marked.lexer(content) const slugify = window.Docsify.slugify const index = {} let slug tokens.forEach(token => { - if (token.type === 'heading' && token.depth <= 2) { + if (token.type === 'heading' && token.depth <= depth) { slug = router.toURL(path, { id: slugify(token.text) }) index[slug] = { slug, title: token.text, body: '' } } else { @@ -154,7 +154,7 @@ export function init (config, vm) { helper .get(vm.router.getFile(path)) .then(result => { - INDEXS[path] = genIndex(path, result, vm.router) + INDEXS[path] = genIndex(path, result, vm.router, config.depth) len === ++count && saveData(config.maxAge) }) })