diff --git a/.codesandbox/ci.json b/.codesandbox/ci.json new file mode 100644 index 000000000..840528450 --- /dev/null +++ b/.codesandbox/ci.json @@ -0,0 +1,4 @@ +{ + "sandboxes": ["2d17z"], + "packages": [".", "packages/docsify-server-renderer"] +} diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..80f989d97 --- /dev/null +++ b/.editorconfig @@ -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 diff --git a/.eslintrc.js b/.eslintrc.js index 087ae9e76..d08568536 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -19,6 +19,7 @@ module.exports = { rules: { 'prettier/prettier': ['error'], camelcase: ['warn'], + 'no-useless-escape': ['warn'], curly: ['error', 'all'], 'dot-notation': ['error'], eqeqeq: ['error'], diff --git a/.github/semantic.yml b/.github/semantic.yml new file mode 100644 index 000000000..e7f5bb59b --- /dev/null +++ b/.github/semantic.yml @@ -0,0 +1,4 @@ +titleAndCommits: true +allowMergeCommits: true +allowRevertCommits: true +anyCommit: true diff --git a/build/build.js b/build/build.js index 6fa2b123b..7dfa6b536 100644 --- a/build/build.js +++ b/build/build.js @@ -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 + * }} opts + */ +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,8 +76,8 @@ 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' }) @@ -73,47 +85,59 @@ const buildAllPlugin = function () { 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) + 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) +}) + diff --git a/build/css.js b/build/css.js index 060506421..2214f3fe4 100644 --- a/build/css.js +++ b/build/css.js @@ -5,8 +5,8 @@ const {spawn} = require('child_process') const args = process.argv.slice(2) fs.readdir(path.join(__dirname, '../src/themes'), (err, files) => { if (err) { - console.log('err', err) - return + console.error('err', err) + process.exit(1) } files.map(async (file) => { if (/\.styl/g.test(file)) { @@ -31,11 +31,17 @@ fs.readdir(path.join(__dirname, '../src/themes'), (err, files) => { }); stylusCMD.on('close', (code) => { - console.log(`[Stylus Build ] child process exited with code ${code}`); + const message = `[Stylus Build ] child process exited with code ${code}` + + if (code !== 0) { + console.error(message); + process.exit(code) + } + console.log(message); }); } else { return } }) -}) \ No newline at end of file +}) diff --git a/build/mincss.js b/build/mincss.js index f6c5ec215..0c9c72280 100644 --- a/build/mincss.js +++ b/build/mincss.js @@ -8,5 +8,8 @@ files.forEach(file => { file = path.resolve('lib/themes', file) cssnano(fs.readFileSync(file)).then(result => { fs.writeFileSync(file, result.css) + }).catch(e => { + console.error(e) + process.exit(1) }) }) diff --git a/build/ssr.js b/build/ssr.js index 16b93cac4..01fdd0518 100644 --- a/build/ssr.js +++ b/build/ssr.js @@ -24,11 +24,12 @@ rollup var dest = 'packages/docsify-server-renderer/build.js' console.log(dest) - bundle.write({ + return bundle.write({ format: 'cjs', file: dest }) }) .catch(function (err) { console.error(err) + process.exit(1) }) diff --git a/cypress/fixtures/tpl/docs.index.html b/cypress/fixtures/tpl/docs.index.html index 94d9526e1..6a8b41a4c 100644 --- a/cypress/fixtures/tpl/docs.index.html +++ b/cypress/fixtures/tpl/docs.index.html @@ -16,7 +16,7 @@ diff --git a/docs/_media/example-with-yaml.md b/docs/_media/example-with-yaml.md new file mode 100644 index 000000000..081bedde2 --- /dev/null +++ b/docs/_media/example-with-yaml.md @@ -0,0 +1,6 @@ +--- +author: John Smith +date: 2020-1-1 +--- + +> This is from the `example.md` diff --git a/docs/configuration.md b/docs/configuration.md index 11797c794..371ed35f6 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -1,6 +1,6 @@ # Configuration -You can configure the `window.$docsify`. +You can configure Docsify by defining `window.$docsify` as an object: ```html ``` +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 + +``` + ## el - Type: `String` @@ -144,6 +162,16 @@ window.$docsify = { }; ``` +If you have a link to the homepage in the sidebar and want it to be shown as active when accessing the root url, make sure to update your sidebar accordingly: + +```markdown +- Sidebar + - [Home](/) + - [Another page](another.md) +``` + +For more details, see [#1131](https://github.com/docsifyjs/docsify/issues/1131). + ## basePath - Type: `String` @@ -265,7 +293,7 @@ window.$docsify = { - Type: `String` - Default: `window.location.pathname` -The name of the link. +The URL that the website `name` links to. ```js window.$docsify = { @@ -446,11 +474,11 @@ window.$docsify = { - type: `String` - default: `noopener` -Default `'noopener'` (no opener) prevents the newly opened external page (when [externalLinkTarget](#externallinktarget) is `'_blank'`) from having the ability to control our page. No `rel` is set when its not `'_blank'`. +Default `'noopener'` (no opener) prevents the newly opened external page (when [externalLinkTarget](#externallinktarget) is `'_blank'`) from having the ability to control our page. No `rel` is set when its not `'_blank'`. See [this post](https://mathiasbynens.github.io/rel-noopener/) for more information about why you may want to use this option. ```js window.$docsify = { - externalLinkTarget: '', // default: 'noopener' + externalLinkRel: '', // default: 'noopener' }; ``` @@ -587,4 +615,4 @@ Adds a space on top when scrolling content page to reach the selected section. T window.$docsify = { topMargin: 90, // default: 0 }; -``` \ No newline at end of file +``` diff --git a/docs/embed-files.md b/docs/embed-files.md index dab2efe4e..d50387477 100644 --- a/docs/embed-files.md +++ b/docs/embed-files.md @@ -39,7 +39,20 @@ You will get it [filename](_media/example.md ':include :type=code') +## Markdown with YAML Front Matter + +When using Markdown, YAML front matter will be stripped from the rendered content. The attributes cannot be used in this case. + +```markdown +[filename](_media/example-with-yaml.md ':include') +``` + +You will get just the content + +[filename](_media/example-with-yaml.md ':include') + ## Embedded code fragments + Sometimes you don't want to embed a whole file. Maybe because you need just a few lines but you want to compile and test the file in CI. ```markdown @@ -53,7 +66,6 @@ Example: [filename](_media/example.js ':include :type=code :fragment=demo') - ## Tag attribute If you embed the file as `iframe`, `audio` and `video`, then you may need to set the attributes of these tags. diff --git a/docs/helpers.md b/docs/helpers.md index 83c59784a..9cb511f96 100644 --- a/docs/helpers.md +++ b/docs/helpers.md @@ -65,6 +65,14 @@ You will get `link`html. Do not worry, you can still set ti [link](/demo ':disabled') ``` +## Cross-Origin link + +Only when you both set the `routerMode: 'history'` and `externalLinkTarget: '_self'`, you need add this configuration for those Cross-Origin links. + +```md +[example.com](https://example.com/ ':crossorgin') +``` + ## Github Task Lists ```md diff --git a/docs/index.html b/docs/index.html index 39c32b814..050b21dde 100644 --- a/docs/index.html +++ b/docs/index.html @@ -9,14 +9,14 @@ - + - + - +