mirror of
https://github.com/wahyd4/docsify.git
synced 2026-08-22 19:56:52 +10:00
39 lines
1.0 KiB
JavaScript
39 lines
1.0 KiB
JavaScript
import { init as initComponet, update as updateComponent } from './component'
|
|
import { init as initSearch } from './search'
|
|
|
|
const CONFIG = {
|
|
placeholder: 'Type to search',
|
|
noData: 'No Results!',
|
|
paths: 'auto',
|
|
depth: 2,
|
|
maxAge: 86400000 // 1 day
|
|
}
|
|
|
|
const install = function (hook, vm) {
|
|
const { util } = Docsify
|
|
const opts = vm.config.search || CONFIG
|
|
|
|
if (Array.isArray(opts)) {
|
|
CONFIG.paths = opts
|
|
} else if (typeof opts === 'object') {
|
|
CONFIG.paths = Array.isArray(opts.paths) ? opts.paths : 'auto'
|
|
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'
|
|
|
|
hook.mounted(_ => {
|
|
initComponet(CONFIG, vm)
|
|
!isAuto && initSearch(CONFIG, vm)
|
|
})
|
|
hook.doneEach(_ => {
|
|
updateComponent(CONFIG, vm)
|
|
isAuto && initSearch(CONFIG, vm)
|
|
})
|
|
}
|
|
|
|
$docsify.plugins = [].concat(install, $docsify.plugins)
|