|
1 | 1 | import {merge, hyphenate, isPrimitive, hasOwn} from './util/core'
|
2 | 2 |
|
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 | + ) |
31 | 32 |
|
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] |
37 | 38 |
|
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)) |
42 | 43 |
|
43 |
| - if (isPrimitive(val)) { |
44 |
| - config[prop] = val === '' ? true : val |
| 44 | + if (isPrimitive(val)) { |
| 45 | + config[prop] = val === '' ? true : val |
| 46 | + } |
45 | 47 | }
|
46 | 48 | }
|
47 |
| - } |
48 | 49 |
|
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 | + } |
63 | 65 | }
|
64 |
| -} |
65 | 66 |
|
66 |
| -window.$docsify = config |
| 67 | + window.$docsify = config |
67 | 68 |
|
68 |
| -export default config |
| 69 | + return config |
| 70 | +} |
0 commit comments