Skip to content

Commit e4e011c

Browse files
committed
fix: async install config, fixed #425
1 parent ef1b42b commit e4e011c

File tree

2 files changed

+60
-58
lines changed

2 files changed

+60
-58
lines changed

src/core/config.js

+59-57
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,70 @@
11
import {merge, hyphenate, isPrimitive, hasOwn} from './util/core'
22

3-
const config = merge(
4-
{
5-
el: '#app',
6-
repo: '',
7-
maxLevel: 6,
8-
subMaxLevel: 0,
9-
loadSidebar: null,
10-
loadNavbar: null,
11-
homepage: 'README.md',
12-
coverpage: '',
13-
basePath: '',
14-
auto2top: false,
15-
name: '',
16-
themeColor: '',
17-
nameLink: window.location.pathname,
18-
autoHeader: false,
19-
executeScript: null,
20-
noEmoji: false,
21-
ga: '',
22-
ext: '.md',
23-
mergeNavbar: false,
24-
formatUpdated: '',
25-
externalLinkTarget: '_blank',
26-
routerMode: 'hash',
27-
noCompileLinks: []
28-
},
29-
window.$docsify
30-
)
3+
export default function () {
4+
const config = merge(
5+
{
6+
el: '#app',
7+
repo: '',
8+
maxLevel: 6,
9+
subMaxLevel: 0,
10+
loadSidebar: null,
11+
loadNavbar: null,
12+
homepage: 'README.md',
13+
coverpage: '',
14+
basePath: '',
15+
auto2top: false,
16+
name: '',
17+
themeColor: '',
18+
nameLink: window.location.pathname,
19+
autoHeader: false,
20+
executeScript: null,
21+
noEmoji: false,
22+
ga: '',
23+
ext: '.md',
24+
mergeNavbar: false,
25+
formatUpdated: '',
26+
externalLinkTarget: '_blank',
27+
routerMode: 'hash',
28+
noCompileLinks: []
29+
},
30+
window.$docsify
31+
)
3132

32-
const script =
33-
document.currentScript ||
34-
[].slice
35-
.call(document.getElementsByTagName('script'))
36-
.filter(n => /docsify\./.test(n.src))[0]
33+
const script =
34+
document.currentScript ||
35+
[].slice
36+
.call(document.getElementsByTagName('script'))
37+
.filter(n => /docsify\./.test(n.src))[0]
3738

38-
if (script) {
39-
for (const prop in config) {
40-
if (hasOwn.call(config, prop)) {
41-
const val = script.getAttribute('data-' + hyphenate(prop))
39+
if (script) {
40+
for (const prop in config) {
41+
if (hasOwn.call(config, prop)) {
42+
const val = script.getAttribute('data-' + hyphenate(prop))
4243

43-
if (isPrimitive(val)) {
44-
config[prop] = val === '' ? true : val
44+
if (isPrimitive(val)) {
45+
config[prop] = val === '' ? true : val
46+
}
4547
}
4648
}
47-
}
4849

49-
if (config.loadSidebar === true) {
50-
config.loadSidebar = '_sidebar' + config.ext
51-
}
52-
if (config.loadNavbar === true) {
53-
config.loadNavbar = '_navbar' + config.ext
54-
}
55-
if (config.coverpage === true) {
56-
config.coverpage = '_coverpage' + config.ext
57-
}
58-
if (config.repo === true) {
59-
config.repo = ''
60-
}
61-
if (config.name === true) {
62-
config.name = ''
50+
if (config.loadSidebar === true) {
51+
config.loadSidebar = '_sidebar' + config.ext
52+
}
53+
if (config.loadNavbar === true) {
54+
config.loadNavbar = '_navbar' + config.ext
55+
}
56+
if (config.coverpage === true) {
57+
config.coverpage = '_coverpage' + config.ext
58+
}
59+
if (config.repo === true) {
60+
config.repo = ''
61+
}
62+
if (config.name === true) {
63+
config.name = ''
64+
}
6365
}
64-
}
6566

66-
window.$docsify = config
67+
window.$docsify = config
6768

68-
export default config
69+
return config
70+
}

src/core/init/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {isFn} from '../util/core'
99
export function initMixin(proto) {
1010
proto._init = function () {
1111
const vm = this
12-
vm.config = config || {}
12+
vm.config = config()
1313

1414
initLifecycle(vm) // Init hooks
1515
initPlugin(vm) // Install plugins

0 commit comments

Comments
 (0)