fix: async install config, fixed #425

This commit is contained in:
qingwei.li 2018-03-19 09:56:29 +08:00
commit e4e011c81f
2 changed files with 61 additions and 59 deletions

View file

@ -1,68 +1,70 @@
import {merge, hyphenate, isPrimitive, hasOwn} from './util/core' import {merge, hyphenate, isPrimitive, hasOwn} from './util/core'
const config = merge( export default function () {
{ const config = merge(
el: '#app', {
repo: '', el: '#app',
maxLevel: 6, repo: '',
subMaxLevel: 0, maxLevel: 6,
loadSidebar: null, subMaxLevel: 0,
loadNavbar: null, loadSidebar: null,
homepage: 'README.md', loadNavbar: null,
coverpage: '', homepage: 'README.md',
basePath: '', coverpage: '',
auto2top: false, basePath: '',
name: '', auto2top: false,
themeColor: '', name: '',
nameLink: window.location.pathname, themeColor: '',
autoHeader: false, nameLink: window.location.pathname,
executeScript: null, autoHeader: false,
noEmoji: false, executeScript: null,
ga: '', noEmoji: false,
ext: '.md', ga: '',
mergeNavbar: false, ext: '.md',
formatUpdated: '', mergeNavbar: false,
externalLinkTarget: '_blank', formatUpdated: '',
routerMode: 'hash', externalLinkTarget: '_blank',
noCompileLinks: [] routerMode: 'hash',
}, noCompileLinks: []
window.$docsify },
) window.$docsify
)
const script = const script =
document.currentScript || document.currentScript ||
[].slice [].slice
.call(document.getElementsByTagName('script')) .call(document.getElementsByTagName('script'))
.filter(n => /docsify\./.test(n.src))[0] .filter(n => /docsify\./.test(n.src))[0]
if (script) { if (script) {
for (const prop in config) { for (const prop in config) {
if (hasOwn.call(config, prop)) { if (hasOwn.call(config, prop)) {
const val = script.getAttribute('data-' + hyphenate(prop)) const val = script.getAttribute('data-' + hyphenate(prop))
if (isPrimitive(val)) { if (isPrimitive(val)) {
config[prop] = val === '' ? true : val config[prop] = val === '' ? true : val
}
} }
} }
if (config.loadSidebar === true) {
config.loadSidebar = '_sidebar' + config.ext
}
if (config.loadNavbar === true) {
config.loadNavbar = '_navbar' + config.ext
}
if (config.coverpage === true) {
config.coverpage = '_coverpage' + config.ext
}
if (config.repo === true) {
config.repo = ''
}
if (config.name === true) {
config.name = ''
}
} }
if (config.loadSidebar === true) { window.$docsify = config
config.loadSidebar = '_sidebar' + config.ext
} return config
if (config.loadNavbar === true) {
config.loadNavbar = '_navbar' + config.ext
}
if (config.coverpage === true) {
config.coverpage = '_coverpage' + config.ext
}
if (config.repo === true) {
config.repo = ''
}
if (config.name === true) {
config.name = ''
}
} }
window.$docsify = config
export default config

View file

@ -9,7 +9,7 @@ import {isFn} from '../util/core'
export function initMixin(proto) { export function initMixin(proto) {
proto._init = function () { proto._init = function () {
const vm = this const vm = this
vm.config = config || {} vm.config = config()
initLifecycle(vm) // Init hooks initLifecycle(vm) // Init hooks
initPlugin(vm) // Install plugins initPlugin(vm) // Install plugins