diff --git a/src/core/config.js b/src/core/config.js index 5c2354cb..0a8763a8 100644 --- a/src/core/config.js +++ b/src/core/config.js @@ -1,68 +1,70 @@ import {merge, hyphenate, isPrimitive, hasOwn} from './util/core' -const config = merge( - { - el: '#app', - repo: '', - maxLevel: 6, - subMaxLevel: 0, - loadSidebar: null, - loadNavbar: null, - homepage: 'README.md', - coverpage: '', - basePath: '', - auto2top: false, - name: '', - themeColor: '', - nameLink: window.location.pathname, - autoHeader: false, - executeScript: null, - noEmoji: false, - ga: '', - ext: '.md', - mergeNavbar: false, - formatUpdated: '', - externalLinkTarget: '_blank', - routerMode: 'hash', - noCompileLinks: [] - }, - window.$docsify -) +export default function () { + const config = merge( + { + el: '#app', + repo: '', + maxLevel: 6, + subMaxLevel: 0, + loadSidebar: null, + loadNavbar: null, + homepage: 'README.md', + coverpage: '', + basePath: '', + auto2top: false, + name: '', + themeColor: '', + nameLink: window.location.pathname, + autoHeader: false, + executeScript: null, + noEmoji: false, + ga: '', + ext: '.md', + mergeNavbar: false, + formatUpdated: '', + externalLinkTarget: '_blank', + routerMode: 'hash', + noCompileLinks: [] + }, + window.$docsify + ) -const script = - document.currentScript || - [].slice - .call(document.getElementsByTagName('script')) - .filter(n => /docsify\./.test(n.src))[0] + const script = + document.currentScript || + [].slice + .call(document.getElementsByTagName('script')) + .filter(n => /docsify\./.test(n.src))[0] -if (script) { - for (const prop in config) { - if (hasOwn.call(config, prop)) { - const val = script.getAttribute('data-' + hyphenate(prop)) + if (script) { + for (const prop in config) { + if (hasOwn.call(config, prop)) { + const val = script.getAttribute('data-' + hyphenate(prop)) - if (isPrimitive(val)) { - config[prop] = val === '' ? true : val + if (isPrimitive(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) { - 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 = '' - } + window.$docsify = config + + return config } - -window.$docsify = config - -export default config diff --git a/src/core/init/index.js b/src/core/init/index.js index a8e8800f..fe88c31d 100644 --- a/src/core/init/index.js +++ b/src/core/init/index.js @@ -9,7 +9,7 @@ import {isFn} from '../util/core' export function initMixin(proto) { proto._init = function () { const vm = this - vm.config = config || {} + vm.config = config() initLifecycle(vm) // Init hooks initPlugin(vm) // Install plugins