refactor(plugins): update search plugin
This commit is contained in:
parent
86594a3118
commit
079bd00395
22 changed files with 348 additions and 393 deletions
|
|
@ -39,4 +39,6 @@ if (script) {
|
|||
if (config.name === true) config.name = ''
|
||||
}
|
||||
|
||||
window.$docsify = config
|
||||
|
||||
export default config
|
||||
|
|
|
|||
|
|
@ -45,8 +45,8 @@ export function scrollActiveSidebar () {
|
|||
const li = nav[last.getAttribute('data-id')]
|
||||
|
||||
if (!li || li === active) return
|
||||
if (active) active.classList.remove('active')
|
||||
|
||||
active && active.classList.remove('active')
|
||||
li.classList.add('active')
|
||||
active = li
|
||||
|
||||
|
|
@ -79,7 +79,7 @@ export function scrollActiveSidebar () {
|
|||
|
||||
export function scrollIntoView (id) {
|
||||
const section = dom.find('#' + id)
|
||||
section && setTimeout(() => section.scrollIntoView(), 0)
|
||||
section && section.scrollIntoView()
|
||||
}
|
||||
|
||||
const scrollEl = dom.$.scrollingElement || dom.$.documentElement
|
||||
|
|
|
|||
|
|
@ -57,15 +57,16 @@ export function fetchMixin (proto) {
|
|||
.then(text => this._renderCover(text))
|
||||
}
|
||||
|
||||
proto.$fetch = function () {
|
||||
proto.$fetch = function (cb = noop) {
|
||||
this._fetchCover()
|
||||
this._fetch(result => {
|
||||
this.$resetEvents()
|
||||
callHook(this, 'doneEach')
|
||||
cb()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export function initFetch (vm) {
|
||||
vm.$fetch()
|
||||
vm.$fetch(_ => callHook(vm, 'ready'))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import * as util from './util'
|
||||
import * as dom from './util/dom'
|
||||
import * as render from './render/compiler'
|
||||
import * as route from './route/util'
|
||||
import * as route from './route/hash'
|
||||
import { get } from './fetch/ajax'
|
||||
import marked from 'marked'
|
||||
import prism from 'prismjs'
|
||||
|
|
|
|||
|
|
@ -25,4 +25,5 @@ initGlobalAPI()
|
|||
/**
|
||||
* Run Docsify
|
||||
*/
|
||||
new Docsify()
|
||||
|
||||
setTimeout(_ => new Docsify(), 0)
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ export function initMixin (proto) {
|
|||
initEvent(vm) // Bind events
|
||||
initRoute(vm) // Add hashchange eventListener
|
||||
initFetch(vm) // Fetch data
|
||||
callHook(vm, 'ready')
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import { genTree } from './gen-tree'
|
|||
import { slugify, clearSlugCache } from './slugify'
|
||||
import { emojify } from './emojify'
|
||||
import { toURL, parse } from '../route/hash'
|
||||
import { getBasePath, isResolvePath, getPath } from '../route/util'
|
||||
import { getBasePath, isAbsolutePath, getPath } from '../route/util'
|
||||
import { isFn, merge, cached } from '../util/core'
|
||||
|
||||
let markdownCompiler = marked
|
||||
|
|
@ -87,7 +87,7 @@ renderer.image = function (href, title, text) {
|
|||
let url = href
|
||||
const titleHTML = title ? ` title="${title}"` : ''
|
||||
|
||||
if (!isResolvePath(href)) {
|
||||
if (!isAbsolutePath(href)) {
|
||||
url = getPath(contentBase, href)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import cssVars from '../util/polyfill/css-vars'
|
|||
import * as tpl from './tpl'
|
||||
import { markdown, sidebar, subSidebar, cover } from './compiler'
|
||||
import { callHook } from '../init/lifecycle'
|
||||
import { getBasePath, getPath, isResolvePath } from '../route/util'
|
||||
import { getBasePath, getPath, isAbsolutePath } from '../route/util'
|
||||
|
||||
function executeScript () {
|
||||
const script = dom.findAll('.markdown-section>script')
|
||||
|
|
@ -101,7 +101,7 @@ export function renderMixin (proto) {
|
|||
let path = m[1]
|
||||
|
||||
dom.toggleClass(el, 'add', 'has-mask')
|
||||
if (isResolvePath(m[1])) {
|
||||
if (isAbsolutePath(m[1])) {
|
||||
path = getPath(getBasePath(this.config.basePath), m[1])
|
||||
}
|
||||
el.style.backgroundImage = `url(${path})`
|
||||
|
|
@ -157,4 +157,5 @@ export function initRender (vm) {
|
|||
// Polyfll
|
||||
cssVars(config.themeColor)
|
||||
}
|
||||
dom.toggleClass(dom.body, 'ready')
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { merge, cached } from '../util/core'
|
||||
import { parseQuery, stringifyQuery, cleanPath } from './util'
|
||||
export * from './util'
|
||||
|
||||
function replaceHash (path) {
|
||||
const i = window.location.href.indexOf('#')
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
import { normalize, parse } from './hash'
|
||||
import { getBasePath, getPath } from './util'
|
||||
import { getBasePath, getPath, isAbsolutePath } from './util'
|
||||
import { on } from '../util/dom'
|
||||
|
||||
function getAlias (path, alias) {
|
||||
if (alias[path]) return getAlias(alias[path], alias)
|
||||
return path
|
||||
return alias[path] ? getAlias(alias[path], alias) : path
|
||||
}
|
||||
|
||||
function getFileName (path) {
|
||||
|
|
@ -24,7 +23,7 @@ export function routeMixin (proto) {
|
|||
path = getAlias(path, config.alias)
|
||||
path = getFileName(path)
|
||||
path = path === '/README.md' ? (config.homepage || path) : path
|
||||
path = getPath(base, path)
|
||||
path = isAbsolutePath(path) ? path : getPath(base, path)
|
||||
|
||||
return path
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ export function stringifyQuery (obj) {
|
|||
const qs = []
|
||||
|
||||
for (const key in obj) {
|
||||
qs.push(`${encode(key)}=${encode(obj[key])}`)
|
||||
qs.push(`${encode(key)}=${encode(obj[key])}`.toLowerCase())
|
||||
}
|
||||
|
||||
return qs.length ? `?${qs.join('&')}` : ''
|
||||
|
|
@ -41,8 +41,8 @@ export function getPath (...args) {
|
|||
return cleanPath(args.join('/'))
|
||||
}
|
||||
|
||||
export const isResolvePath = cached(path => {
|
||||
return /:|(\/{2})/.test(path)
|
||||
export const isAbsolutePath = cached(path => {
|
||||
return /(:|(\/{2}))/.test(path)
|
||||
})
|
||||
|
||||
export const getRoot = cached(path => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue