Skip to content

Commit

Permalink
chore: syncing
Browse files Browse the repository at this point in the history
  • Loading branch information
anikethsaha committed Jun 14, 2020
2 parents 1e3dd13 + da9af18 commit c21ced4
Show file tree
Hide file tree
Showing 48 changed files with 5,000 additions and 3,934 deletions.
4 changes: 4 additions & 0 deletions .codesandbox/ci.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"sandboxes": ["2d17z"],
"packages": [".", "packages/docsify-server-renderer"]
}
11 changes: 11 additions & 0 deletions .editorconfig
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
4 changes: 4 additions & 0 deletions .github/semantic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
titleAndCommits: true
allowMergeCommits: true
allowRevertCommits: true
anyCommit: true
122 changes: 73 additions & 49 deletions build/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
async function build(opts) {
await rollup
.rollup({
input: opts.input,
plugins: (opts.plugins || []).concat([
Expand All @@ -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'},
Expand All @@ -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)
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)
})

14 changes: 10 additions & 4 deletions build/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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
}

})
})
})
3 changes: 3 additions & 0 deletions build/mincss.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
3 changes: 2 additions & 1 deletion build/ssr.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
2 changes: 1 addition & 1 deletion cypress/fixtures/tpl/docs.index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<meta name="description" content="A magical documentation generator." />
<meta
name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"
content="width=device-width, initial-scale=1.0, minimum-scale=1.0"
/>
<link rel="stylesheet" href="lib/themes/vue.css" title="vue" />
<link rel="stylesheet" href="lib/themes/dark.css" title="dark" disabled />
Expand Down
6 changes: 6 additions & 0 deletions docs/_media/example-with-yaml.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
author: John Smith
date: 2020-1-1
---

> This is from the `example.md`
34 changes: 31 additions & 3 deletions docs/configuration.md
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>
Expand All @@ -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>
```

## el

- Type: `String`
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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'
};
```

Expand Down
2 changes: 0 additions & 2 deletions docs/cover.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ Set `coverpage` to **true**, and create a `_coverpage.md`:
[Get Started](#docsify)
```

!> A document site can have only one coverpage!

## Custom background

The background color is generated randomly by default. You can customize the background color or a background image:
Expand Down
14 changes: 13 additions & 1 deletion docs/embed-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions docs/helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ You will get `<a href="/demo/">link</a>`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
Expand Down
Loading

0 comments on commit c21ced4

Please sign in to comment.