Skip to content

Commit b7b589b

Browse files
committed
feat(search): Supports the max depth of the search headline, fixed #223, resolve #129
1 parent 0dd2497 commit b7b589b

File tree

5 files changed

+17
-6
lines changed

5 files changed

+17
-6
lines changed

docs/de-de/plugins.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ Als Standardeinstellung werden Hyperlinks auf der aktuellen Seite erkannt und de
3535
noData: {
3636
'/de-de/': 'Keine Ergebnisse',
3737
'/': 'No Results'
38-
}
38+
},
39+
40+
// Headline depth, 1 - 6
41+
depth: 2
3942
}
4043
}
4144
</script>

docs/plugins.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ By default, the hyperlink on the current page is recognized and the content is s
3535
noData: {
3636
'/zh-cn/': '找不到结果',
3737
'/': 'No Results'
38-
}
38+
},
39+
40+
// Headline depth, 1 - 6
41+
depth: 2
3942
}
4043
}
4144
</script>

docs/zh-cn/plugins.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@
3535
noData: {
3636
'/zh-cn/': '找不到结果',
3737
'/': 'No Results'
38-
}
38+
},
39+
40+
// 搜索标题的最大程级, 1 - 6
41+
depth: 2
3942
}
4043
}
4144
</script>

src/plugins/search/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const CONFIG = {
55
placeholder: 'Type to search',
66
noData: 'No Results!',
77
paths: 'auto',
8+
depth: 2,
89
maxAge: 86400000 // 1 day
910
}
1011

@@ -19,6 +20,7 @@ const install = function (hook, vm) {
1920
CONFIG.maxAge = util.isPrimitive(opts.maxAge) ? opts.maxAge : CONFIG.maxAge
2021
CONFIG.placeholder = opts.placeholder || CONFIG.placeholder
2122
CONFIG.noData = opts.noData || CONFIG.noData
23+
CONFIG.depth = opts.depth || CONFIG.depth
2224
}
2325

2426
const isAuto = CONFIG.paths === 'auto'

src/plugins/search/search.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ function saveData (maxAge) {
3838
localStorage.setItem('docsify.search.index', JSON.stringify(INDEXS))
3939
}
4040

41-
export function genIndex (path, content = '', router) {
41+
export function genIndex (path, content = '', router, depth) {
4242
const tokens = window.marked.lexer(content)
4343
const slugify = window.Docsify.slugify
4444
const index = {}
4545
let slug
4646

4747
tokens.forEach(token => {
48-
if (token.type === 'heading' && token.depth <= 2) {
48+
if (token.type === 'heading' && token.depth <= depth) {
4949
slug = router.toURL(path, { id: slugify(token.text) })
5050
index[slug] = { slug, title: token.text, body: '' }
5151
} else {
@@ -154,7 +154,7 @@ export function init (config, vm) {
154154
helper
155155
.get(vm.router.getFile(path))
156156
.then(result => {
157-
INDEXS[path] = genIndex(path, result, vm.router)
157+
INDEXS[path] = genIndex(path, result, vm.router, config.depth)
158158
len === ++count && saveData(config.maxAge)
159159
})
160160
})

0 commit comments

Comments
 (0)