-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Expand file tree
/
Copy pathconfig.js
More file actions
223 lines (196 loc) Β· 6.28 KB
/
config.js
File metadata and controls
223 lines (196 loc) Β· 6.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
import { stripIndent } from 'common-tags';
import { hyphenate, isPrimitive } from './util/core.js';
/** @import { Docsify } from './Docsify.js' */
/** @import { Hooks } from './init/lifecycle.js' */
const currentScript = document.currentScript;
const defaultDocsifyConfig = () => ({
alias: /** @type {Record<string, string>} */ ({}),
auto2top: false,
autoHeader: false,
basePath: '',
catchPluginErrors: true,
cornerExternalLinkTarget:
/** @type {'_blank' | '_self' | '_parent' | '_top' | '_unfencedTop'} */ (
'_blank'
),
coverpage: /** @type {boolean | string} */ (''),
el: '#app',
executeScript: /** @type {null | boolean} */ (null),
ext: '.md',
externalLinkRel: /** @type {'noopener' | string} */ ('noopener'), // TODO string union type based on spec
externalLinkTarget:
/** @type {'_blank' | '_self' | '_parent' | '_top' | '_unfencedTop'} */ (
'_blank'
),
fallbackLanguages: /** @type {null | string[]} */ (null),
fallbackDefaultLanguage: '',
formatUpdated: /** @type {string | ((updatedAt: string) => string)} */ (''),
pageTitleFormatter: /** @type {null | ((name: string) => string)} */ (null),
/** For the frontmatter plugin. */
frontMatter: /** @type {Record<string, TODO> | null} */ (null),
hideSidebar: false,
homepage: 'README.md',
keyBindings:
/** @type {false | { [commandName: string]: { bindings: string[]; callback: Function } }} */ ({}),
loadNavbar: /** @type {null | boolean | string} */ (null),
loadSidebar: /** @type {null | boolean | string} */ (null),
logo: false,
markdown: null,
maxLevel: 6,
mergeNavbar: false,
name: /** @type {boolean | string} */ (''),
nameLink: window.location.pathname,
nativeEmoji: false,
noCompileLinks: /** @type {string[]} */ ([]),
noEmoji: false,
notFoundPage: /** @type {boolean | string | Record<string, string>} */ (
false
),
onlyCover: false,
plugins: /** @type {Plugin[]} */ ([]),
relativePath: false,
repo: /** @type {string} */ (''),
requestHeaders: /** @type {Record<string, string>} */ ({}),
routerMode: /** @type {'hash' | 'history'} */ 'hash',
routes: /** @type {Record<string, string | RouteHandler>} */ ({}),
skipLink: /** @type {false | string | Record<string, string>} */ (
'Skip to main content'
),
subMaxLevel: 0,
vueComponents: /** @type {Record<string, TODO>} */ ({}),
vueGlobalOptions: /** @type {Record<string, TODO>} */ ({}),
vueMounts: /** @type {Record<string, TODO>} */ ({}),
// Deprecations //////////////////
/** @deprecated */
get themeColor() {
return this.__themeColor;
},
set themeColor(value) {
if (value) {
this.__themeColor = value;
// eslint-disable-next-line no-console
console.warn(
stripIndent(`
$docsify.themeColor is deprecated as of v5. Use the "--theme-color" CSS property to customize your theme color.
<style>
:root {
--theme-color: deeppink;
}
</style>
`).trim(),
);
}
},
__themeColor: '',
/** @deprecated */
get topMargin() {
return this.__topMargin;
},
set topMargin(value) {
if (value) {
this.__topMargin = value;
// eslint-disable-next-line no-console
console.warn(
stripIndent(`
$docsify.topMargin is deprecated as of v5. Use the "--scroll-padding-top" CSS property to specify a scroll margin when using a sticky navbar.
<style>
:root {
--scroll-padding-top: 10px;
}
</style>
`).trim(),
);
}
},
__topMargin: 0,
});
/** @typedef {ReturnType<typeof defaultDocsifyConfig>} DocsifyConfig */
/**
* @param {import('./Docsify.js').Docsify} vm
* @param {Partial<DocsifyConfig>} config
* @returns {DocsifyConfig}
*/
export default function (vm, config = {}) {
config = Object.assign(
defaultDocsifyConfig(),
// Handle non-function configs no matter what (f.e. plugins assign options onto it)
window.$docsify,
// Also handle function config (the app can specificy a function, and plugins will assign options onto it)
typeof window.$docsify === 'function' ? window.$docsify(vm) : undefined,
// Finally, user config passed directly to the instance has priority.
config,
);
// Merge default and user-specified key bindings
if (config.keyBindings !== false) {
config.keyBindings = Object.assign(
// Default
{
toggleSidebar: {
bindings: ['\\'],
callback(/** @type {KeyboardEvent} */ e) {
const toggleElm = /** @type {HTMLElement} */ (
document.querySelector('.sidebar-toggle-button')
);
if (toggleElm) {
toggleElm.click();
}
},
},
},
// User-specified
config.keyBindings,
);
}
const script =
currentScript ||
Array.from(document.getElementsByTagName('script')).filter(n =>
/docsify\./.test(n.src),
)[0];
if (script) {
for (const prop of /** @type {(keyof DocsifyConfig)[]} */ (
Object.keys(config)
)) {
const val = script.getAttribute('data-' + hyphenate(prop));
if (isPrimitive(val)) {
// eslint-disable-next-line no-console
console.warn(
`DEPRECATION: data-* attributes on the docsify global script (f.e. ${
'data-' + hyphenate(prop)
}) are deprecated.`,
);
// @ts-expect-error too dynamic for TS
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.name === true) {
config.name = '';
}
return /** @type {DocsifyConfig} */ (config);
}
/** @typedef {any} TODO */
/** @typedef {(hooks: Hooks, vm: Docsify) => void} Plugin */
/**
@typedef {(
((route: string, matched: RegExpMatchArray) => string) |
((route: string, matched: RegExpMatchArray, next: (markdown?: string) => void) => void)
)} RouteHandler - Given a route, provides the markdown to render for that route.
*/
/**
@typedef {
{
subMaxLevel: number,
themeColor: string,
topMargin: number,
}
} DocsifyConfigOld
*/