Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 5.8k
Allow configs to be functions#1189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
f72bf4cb4b8bdc732c34d5a5b5aab72cb3d7e002bfb40baae1b8a81a88033b679fe3d5dca22f341dc2c731f1a6463f1b88809fda972ec71f0438dd664a231dabaf6f38f3f263146e4c4File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # http://EditorConfig.org | ||
| root = true | ||
| [*] | ||
| charset = utf-8 | ||
| indent_style = space | ||
| indent_size = 2 | ||
| end_of_line = lf | ||
| insert_final_newline = true | ||
| trim_trailing_whitespace = true | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -9,8 +9,16 @@ const version = process.env.VERSION || require('../package.json').version | ||
| const chokidar = require('chokidar') | ||
| const path = require('path') | ||
| const build = function (opts) { | ||
| rollup | ||
| /** | ||
| * @param {{ | ||
| * input: string, | ||
| * output?: string, | ||
| * globalName?: string, | ||
| * plugins?: Array<import('rollup').Plugin> | ||
| * }} opts | ||
| */ | ||
anikethsaha marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| async function build(opts) { | ||
| await rollup | ||
| .rollup({ | ||
| input: opts.input, | ||
| plugins: (opts.plugins || []).concat([ | ||
| @@ -27,31 +35,35 @@ const build = function (opts) { | ||
| var dest = 'lib/' + (opts.output || opts.input) | ||
| console.log(dest) | ||
| bundle.write({ | ||
| return bundle.write({ | ||
| format: 'iife', | ||
| output: opts.globalName ? {name: opts.globalName} : {}, | ||
| file: dest, | ||
| strict: false | ||
| }) | ||
| }) | ||
| .catch(function (err) { | ||
| console.error(err) | ||
| }) | ||
| } | ||
| const buildCore = function () { | ||
| build({ | ||
| async function buildCore() { | ||
| const promises = [] | ||
| promises.push(build({ | ||
| input: 'src/core/index.js', | ||
| output: 'docsify.js' | ||
| }) | ||
| output: 'docsify.js', | ||
| })) | ||
| if (isProd) { | ||
| build({ | ||
| promises.push(build({ | ||
| input: 'src/core/index.js', | ||
| output: 'docsify.min.js', | ||
| plugins: [uglify()] | ||
| }) | ||
| })) | ||
| } | ||
| await Promise.all(promises) | ||
| } | ||
| const buildAllPlugin = function () { | ||
| async function buildAllPlugin() { | ||
| var plugins = [ | ||
| {name: 'search', input: 'search/index.js'}, | ||
| {name: 'ga', input: 'ga.js'}, | ||
| @@ -64,56 +76,68 @@ const buildAllPlugin = function () { | ||
| {name: 'gitalk', input: 'gitalk.js'} | ||
| ] | ||
| plugins.forEach(item => { | ||
| build({ | ||
| const promises = plugins.map(item => { | ||
| return build({ | ||
| input: 'src/plugins/' + item.input, | ||
| output: 'plugins/' + item.name + '.js' | ||
| }) | ||
| }) | ||
| if (isProd) { | ||
| plugins.forEach(item => { | ||
| build({ | ||
| promises.push(build({ | ||
| input: 'src/plugins/' + item.input, | ||
| output: 'plugins/' + item.name + '.min.js', | ||
| plugins: [uglify()] | ||
| }) | ||
| })) | ||
| }) | ||
| } | ||
| await Promise.all(promises) | ||
| } | ||
| if (!isProd) { | ||
| chokidar | ||
| .watch(['src/core', 'src/plugins'], { | ||
| atomic: true, | ||
| awaitWriteFinish: { | ||
| stabilityThreshold: 1000, | ||
| pollInterval: 100 | ||
| } | ||
| }) | ||
| .on('change', p => { | ||
| console.log('[watch] ', p) | ||
| const dirs = p.split(path.sep) | ||
| if (dirs[1] === 'core') { | ||
| buildCore() | ||
| } else if (dirs[2]) { | ||
| const name = path.basename(dirs[2], '.js') | ||
| const input = `src/plugins/${name}${ | ||
| /\.js/.test(dirs[2]) ? '' : '/index' | ||
| }.js` | ||
| async function main() { | ||
| if (!isProd) { | ||
| chokidar | ||
| .watch(['src/core', 'src/plugins'], { | ||
| atomic: true, | ||
| awaitWriteFinish: { | ||
| stabilityThreshold: 1000, | ||
| pollInterval: 100 | ||
| } | ||
| }) | ||
| .on('change', p => { | ||
| console.log('[watch] ', p) | ||
| const dirs = p.split(path.sep) | ||
trusktr marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| if (dirs[1] === 'core') { | ||
| buildCore() | ||
| } else if (dirs[2]) { | ||
| const name = path.basename(dirs[2], '.js') | ||
| const input = `src/plugins/${name}${ | ||
| /\.js/.test(dirs[2]) ? '' : '/index' | ||
| }.js` | ||
| build({ | ||
| input, | ||
| output: 'plugins/' + name + '.js' | ||
| }) | ||
| } | ||
| }) | ||
| .on('ready', () => { | ||
| console.log('[start]') | ||
| buildCore() | ||
| build({ | ||
| input, | ||
| output: 'plugins/' + name + '.js' | ||
| }) | ||
| } | ||
| }) | ||
| .on('ready', () => { | ||
| console.log('[start]') | ||
| buildCore() | ||
| buildAllPlugin() | ||
| }) | ||
| } else { | ||
| await Promise.all([ | ||
| buildCore(), | ||
| buildAllPlugin() | ||
| }) | ||
| } else { | ||
| buildCore() | ||
| buildAllPlugin() | ||
| ]) | ||
| } | ||
| } | ||
| main().catch((e) => { | ||
| console.error(e) | ||
| process.exit(1) | ||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| # Configuration | ||
| You can configure the `window.$docsify`. | ||
| You can configure Docsify by defining `window.$docsify` as an object: | ||
| ```html | ||
| <script> | ||
| @@ -12,6 +12,24 @@ You can configure the `window.$docsify`. | ||
| </script> | ||
| ``` | ||
| The config can also be defined as a function, in which case the first arg is the Docsify `vm` instance. The function should return a config object. This can be useful for referencing `vm` in places like the markdown configuration: | ||
| ```html | ||
| <script> | ||
| window.$docsify = function(vm) { | ||
| return { | ||
| markdown: { | ||
| renderer: { | ||
| code(code, lang) { | ||
| // ... use `vm` ... | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
| </script> | ||
anikethsaha marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| ``` | ||
| ## el | ||
| - Type: `String` | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.