refactor(core): and markdown compiler

This commit is contained in:
qingwei.li 2017-02-18 14:09:17 +08:00 committed by cinwell.li
commit fe88c154b0
12 changed files with 194 additions and 232 deletions

View file

@ -1,14 +1,15 @@
import { get } from './ajax'
import { callHook } from '../init/lifecycle'
import { getCurrentRoot } from '../route/util'
import { getRoot } from '../route/util'
import { noop } from '../util/core'
export function fetchMixin (Docsify) {
let last
Docsify.prototype._fetch = function (cb) {
Docsify.prototype._fetch = function (cb = noop) {
const { path } = this.route
const { loadNavbar, loadSidebar } = this.config
const currentRoot = getCurrentRoot(path)
const root = getRoot(path)
// Abort last request
last && last.abort && last.abort()
@ -21,14 +22,14 @@ export function fetchMixin (Docsify) {
const fn = result => { this._renderSidebar(result); cb() }
// Load sidebar
get(this.$getFile(currentRoot + loadSidebar))
get(this.$getFile(root + loadSidebar))
.then(fn, _ => get(loadSidebar).then(fn))
},
_ => this._renderMain(null))
// Load nav
loadNavbar &&
get(this.$getFile(currentRoot + loadNavbar))
get(this.$getFile(root + loadNavbar))
.then(
this._renderNav,
_ => get(loadNavbar).then(this._renderNav)