Compare commits

...
106 Commits
Author SHA1 Message Date
qingwei.li f943fede99 [release] 4.1.7 2017-05-30 19:40:03 +08:00
qingwei.li e296439df3 [build] 4.1.7 2017-05-30 19:40:02 +08:00
qingwei.li 0014895c19 fix(ssr): clean files 2017-05-30 19:39:39 +08:00
qingwei.li 23590fa7e7 fix typo 2017-05-30 17:58:28 +08:00
qingwei.li 8689a37121 update readme 2017-05-30 16:34:36 +08:00
qingwei.li 05a0211861 update readme 2017-05-30 16:27:13 +08:00
qingwei.li 318189a13f [release] 4.1.6 2017-05-30 16:18:24 +08:00
qingwei.li 42795a0483 [build] 4.1.6 2017-05-30 16:18:23 +08:00
qingwei.li 6b9e0922cf fix(ssr): add debug 2017-05-30 16:16:36 +08:00
qingwei.li 8cb4189b96 update docs 2017-05-30 15:41:34 +08:00
qingwei.li 7eb6346075 [release] 4.1.5 2017-05-30 15:38:44 +08:00
qingwei.li 238e9633f9 [build] 4.1.5 2017-05-30 15:38:44 +08:00
qingwei.li 6db8c9e6c9 fix(ssr): missing package 2017-05-30 15:34:48 +08:00
qingwei.li e160bcaded [release] 4.1.4 2017-05-30 15:28:58 +08:00
qingwei.li 8cf69754b5 [build] 4.1.4 2017-05-30 15:28:58 +08:00
qingwei.li 79a83bc17d fix(ssr): file path 2017-05-30 15:27:04 +08:00
qingwei.li 81c87f7926 update readme 2017-05-30 14:01:06 +08:00
qingwei.li 67ec128315 [release] 4.1.3 2017-05-30 13:58:28 +08:00
qingwei.li 77657e3b64 [build] 4.1.3 2017-05-30 13:58:28 +08:00
qingwei.li 9825db47af fix: update babel config 2017-05-30 13:58:05 +08:00
qingwei.li 1a5593889e [release] 4.1.2 2017-05-30 13:38:44 +08:00
qingwei.li fc9cdf37c5 [build] 4.1.2 2017-05-30 13:38:44 +08:00
qingwei.li 80dba191d3 fix: update babel config 2017-05-30 13:38:20 +08:00
qingwei.li 5a0c37fcd3 [release] 4.1.1 2017-05-30 13:15:13 +08:00
qingwei.li 1462efedcd [build] 4.1.1 2017-05-30 13:15:13 +08:00
qingwei.li 4cb20a5f9d fix: build for ssr package 2017-05-30 13:13:41 +08:00
qingwei.li 490c8a19d3 docs(ssr): update sidebar 2017-05-30 12:55:09 +08:00
qingwei.li 4b838247ea change: update 2017-05-30 12:52:52 +08:00
qingwei.li b091f3f10d docs(ssr): update 2017-05-30 12:36:23 +08:00
qingwei.li 0e74e6c15e fix: remove history mode 2017-05-30 12:16:26 +08:00
qingwei.li be8358fcdc [release] 4.1.0 2017-05-30 12:14:33 +08:00
qingwei.li 1ae0a9a845 [build] 4.1.0 2017-05-30 12:14:33 +08:00
qingwei.li 7e169ad154 docs(changelog): 4.1.0 2017-05-30 12:05:25 +08:00
qingwei.li 8595c99c0b docs(ssr): add ssr 2017-05-30 11:54:37 +08:00
qingwei.li 43fc8b8ab1 [release] 4.0.2 next 2017-05-30 10:14:42 +08:00
qingwei.li ccec23df7f [build] 4.0.2 next 2017-05-30 10:14:41 +08:00
qingwei.li fc1cd3f11d fix: basePath for history mode 2017-05-30 10:11:48 +08:00
qingwei.li 3f38810774 [release] 4.0.1 next 2017-05-30 06:34:35 +08:00
qingwei.li 3db4841da3 [build] 4.0.1 next 2017-05-30 06:34:35 +08:00
qingwei.li b764b6e32c fix: lint 2017-05-30 06:34:16 +08:00
qingwei.li 46261572e3 fix(ssr): remove context 2017-05-30 06:32:41 +08:00
qingwei.li d53b8dadb3 [release] 4.0.0 next 2017-05-30 04:39:43 +08:00
qingwei.li b9b9d87681 [build] 4.0.0 next 2017-05-30 04:39:43 +08:00
qingwei.li d4f6072d10 refactor(ssr): path => context 2017-05-30 04:28:30 +08:00
qingwei.li 891475e132 refactor(ssr): for test 2017-05-30 04:28:30 +08:00
qingwei.li 1acfdd335c refactor(ssr): return promise 2017-05-30 04:28:30 +08:00
qingwei.li 1f4514dcad fix: lint 2017-05-30 04:28:30 +08:00
qingwei.li eba1c987a8 fix(render): init event in ssr 2017-05-30 04:28:30 +08:00
qingwei.li 3444884905 feat: finish ssr 2017-05-30 04:28:30 +08:00
qingwei.li 6dea685fee feat: init ocsify-server-renderer 2017-05-30 04:28:30 +08:00
qingwei.li f095eb888f feat: support history mode 2017-05-30 04:28:30 +08:00
qingwei.li 8741c746df refactor(router): clean global api 2017-05-30 04:28:30 +08:00
qingwei.li 2c7041c8fb refactor(router): dupports multiple mode 2017-05-30 04:28:30 +08:00
Wei Wangandcinwell.li 2a21c40f17 Fix/script in theme (#163)
* Add newline before appended content

* Also add new line to dev page
2017-05-29 15:24:50 +08:00
ubirdandcinwell.li 000194c8da Add vue-amap into README.md (#161)
* Update README.md

* Update README.md
2017-05-25 11:57:37 +08:00
qingwei.li fce1e47131 -> v3.7.3 2017-05-22 20:56:34 +08:00
qingwei.li 6d244139dd bump: 3.7.3 2017-05-22 20:56:25 +08:00
qingwei.li eca3368152 fix(render): find => filter 2017-05-22 20:54:50 +08:00
gpreslandandcinwell.li bab76e004d Pretty dir tree 2017-05-22 08:03:42 +08:00
qingwei.li eb9dc4671a -> v3.7.2 2017-05-19 11:38:08 +08:00
qingwei.li bb815cb2d4 bump: 3.7.2 2017-05-19 11:38:02 +08:00
qingwei.li 26db33dc31 tweaks 2017-05-19 11:36:56 +08:00
qingwei.li 6cbed4b4d8 -> v3.7.1 2017-05-19 08:39:13 +08:00
qingwei.li b948cb06d7 bump: 3.7.1 2017-05-19 08:39:09 +08:00
qingwei.li b2b474264f fix: docsify-updated is undefined 2017-05-19 08:36:45 +08:00
qingwei.li a8c73ee2b9 update yarnlock 2017-05-17 10:41:48 +08:00
qingwei.li eda9bb8343 -> v3.7.0 2017-05-16 23:11:56 +08:00
qingwei.li 50e771e6a8 bump: 3.7.0 2017-05-16 23:11:50 +08:00
qingwei.li 2d73285de5 feat: add externalLinkTarget, close #149 2017-05-16 23:09:41 +08:00
qingwei.li d2be5aecf8 feat: add docsify-updated, close #158 2017-05-16 23:03:22 +08:00
qingwei.li ca0d6182b9 -> v3.6.6 2017-05-06 21:13:10 +08:00
qingwei.li dacea8a39b bump: 3.6.6 2017-05-06 21:13:05 +08:00
qingwei.li da75d70dee feat: support query string for the search, fixed #156 2017-05-06 21:11:04 +08:00
qingwei.li 6ed25cebe5 -> v3.6.5 2017-04-28 09:57:02 +08:00
qingwei.li ee54141776 bump: 3.6.5 2017-04-28 09:56:58 +08:00
qingwei.li 51832d3506 fix(util): fix crash, fixed #154 2017-04-28 09:56:07 +08:00
qingwei.li 25ccc79e56 -> v3.6.4 2017-04-28 08:03:56 +08:00
qingwei.li 890d29f982 bump: 3.6.4 2017-04-28 08:03:49 +08:00
qingwei.li 76c041ad48 fix(util): correctly clean up duplicate slashes, fixed #153 2017-04-28 08:02:54 +08:00
qingwei.li 2c277b8f79 -> v3.6.3 2017-04-25 12:41:29 +08:00
qingwei.li a5f6ccd1d1 bump: 3.6.3 2017-04-25 12:41:16 +08:00
qingwei.li 11c94b2149 changelog 3.6.3 2017-04-25 12:41:02 +08:00
qingwei.li 2653849a3e fix(external-script): script attrs 2017-04-25 12:39:58 +08:00
qingwei.li d7b0d1b949 docs: update cdn 2017-04-25 12:13:56 +08:00
Frances Coronelandcinwell.li 6911fb879b Add hire-me to showcase section 2017-04-21 08:14:22 +08:00
Kiko Beatsandcinwell.li 137a93c7b2 Add JS MythBusters to showcase (#148) 2017-04-17 20:32:38 +08:00
qingwei.li 5d5caa1f89 -> v3.6.2 2017-04-12 23:53:18 +08:00
qingwei.li 1dfd6cdcfe docs: add changelog 2017-04-12 23:53:11 +08:00
qingwei.li 91c6db2902 bump: 3.6.2 2017-04-12 23:52:25 +08:00
qingwei.li 94d6603c06 feat(external-script): detect more than one script dom, fixed #146 2017-04-12 23:51:16 +08:00
qingwei.li 920f624b5c -> v3.6.1 2017-04-12 23:46:46 +08:00
qingwei.li 8fb1350728 bump: 3.6.1 2017-04-12 23:46:46 +08:00
Mehdy Daraandcinwell.li c1df94662a GA: Send hash instead of complete href (#147)
On https://docsify.js.org/#/quickstart

send "#/quickstart" instead of "https://docsify.js.org/#/quickstart"
2017-04-12 23:45:58 +08:00
qingwei.li 9b7e5f5814 feat(event): Collapse the sidebar when click outside element in the small screen 2017-04-09 12:44:23 +08:00
qingwei.li 432bcfb54b -> v3.6.0 2017-04-09 12:12:32 +08:00
qingwei.li 4f98497284 bump: 3.6.0 2017-04-09 12:12:21 +08:00
cinwell.liandGitHub 9220523a40 feat(render): add mergeNavbar option, close #125, #124 (#145) 2017-04-09 12:10:37 +08:00
qingwei.li b8100c0755 -> v3.5.2 2017-04-05 21:31:27 +08:00
qingwei.li be0230ebe9 bump: 3.5.2 2017-04-05 21:31:22 +08:00
cinwell.liandGitHub aa6d2afce8 Merge pull request #143 from bojand/master
Properly handle anchor links local within a file. Fix #142
2017-04-01 10:26:36 +08:00
Bojan Djurkovic a706203879 add optional current route param to toURL and use it to properly compose local anchor links 2017-03-31 09:08:05 -03:00
Bojan Djurkovic fbc75bdb95 fix code style by removing semicolons 2017-03-30 20:37:26 -03:00
Bojan Djurkovic 5af174bd20 in toURL test for anchor links and if so prepend the currentPath to the generated path. fixes #142 2017-03-30 20:26:53 -03:00
qingwei.li e70327ab2b -> v3.5.1 2017-03-25 16:26:11 +08:00
qingwei.li 7209b82982 bump: 3.5.1 2017-03-25 16:26:07 +08:00
qingwei.li 594299ffbd fix: .md file extension regex 2017-03-25 16:25:03 +08:00
76 changed files with 3079 additions and 1587 deletions
+2
View File
@@ -1 +1,3 @@
.git/
packages/docsify-server-renderer/build.js
node_modules
+3
View File
@@ -2,6 +2,9 @@
"extends": [
"vue"
],
"parserOptions": {
"ecmaVersion": 8
},
"env": {
"browser": true
},
+84 -19
View File
@@ -1,96 +1,161 @@
# Changelog
# 3.5.0 / 2017-03-25
## 4.1.0 / 2017-05-30 🎂 to me
* feat: Support server client renderer [See detail](//docsify.js.org/#/ssr)
* feat: Support HTML5 history API. `$docsify.routerMode = 'history'`
* Breaking change: Clean global API
## 3.7.3 / 2017-05-22
* fix(render): find => filter, Compatible with old browser
* Pretty dir tree
## 3.7.2 / 2017-05-19
* tweaks
## 3.7.1 / 2017-05-19
* fix: docsify-updated is undefined
## 3.7.0 / 2017-05-16
* feat: add externalLinkTarget, close ([#149](https://github.com/QingWei-Li/docsify/issues/149)
* feat: add **{docsify-updated<span>}</span>**, close ([#158](https://github.com/QingWei-Li/docsify/issues/158)
## 3.6.6 / 2017-05-06
* feat: support query string for the search, likes `https://docsify.js.org/#/?s=navbar`, fixed ([#156](https://github.com/QingWei-Li/docsify/issues/156)
## 3.6.5 / 2017-04-28
* fix(util): fix crash, fixed ([#154](https://github.com/QingWei-Li/docsify/issues/154)
## 3.6.4 / 2017-04-28
* fix(util): correctly clean up duplicate slashes, fixed ([#153](https://github.com/QingWei-Li/docsify/issues/153)
## 3.6.3 / 2017-04-25
* fix(external-script): script attrs
## 3.6.2/ 2017-04-12
* feat(external-script): detect more than one script dom, fixed ([#146](https://github.com/QingWei-Li/docsify/issues/146)
* GA: Send hash instead of complete href ([#147](https://github.com/QingWei-Li/docsify/issues/147)
## 3.6.1 / 2017-04-09
* feat(event): Collapse the sidebar when click outside element in the small screen
## 3.6.0 / 2017-04-09
* feat(render): add mergeNavbar option, close ([#125](https://github.com/QingWei-Li/docsify/issues/125)
## 3.5.2/ 2017-04-05
* add optional current route param to toURL and use it to properly compose local anchor links
* fix code style by removing semicolons
* in toURL test for anchor links and if so prepend the currentPath to the generated path. fixes ([#142](https://github.com/QingWei-Li/docsify/issues/142))
## 3.5.1 / 2017-03-25
* fix: .md file extension regex
## 3.5.0 / 2017-03-25
* feat(route): auto remove .md extension
* fix: adjust display on small screens [@jrappen](https://github.com/jrappen)
* fix: navbar labels for German [@jrappen](https://github.com/jrappen)
# 3.4.4 / 2017-03-17
## 3.4.4 / 2017-03-17
* fix(search): fix input style
* fix search plugin match bug
# 3.4.3 / 2017-03-16
## 3.4.3 / 2017-03-16
* Add ability to ignore headers when generating toc ([#127](https://github.com/QingWei-Li/docsify/issues/127) [@christopherwk210](https://github.com/christopherwk210))
* fix external-script not inserting script at right place [@Leopoldthecoder](https://github.com/Leopoldthecoder)
* add German docs [@jrappen](https://github.com/jrappen)
# 3.4.2 / 2017-03-11
## 3.4.2 / 2017-03-11
* feat(emojify): add no-emoji option
# 3.4.1 / 2017-03-10
## 3.4.1 / 2017-03-10
* fix(dom): Disable the dom cache when vue is present, fixed [#119](https://github.com/QingWei-Li/docsify/issues/119)
* update english docs, [@jrappen](https://github.com/jrappen)
# 3.4.0 / 2017-03-09
## 3.4.0 / 2017-03-09
* feat(zoom-image): add plugin
# 3.3.0 / 2017-03-07
## 3.3.0 / 2017-03-07
* add front-matter plugin
* add external-script plugin, [@Leopoldthecoder](https://github.com/Leopoldthecoder)
* Fix nav showing while loading ([#112](https://github.com/QingWei-Li/docsify/issues/112))
# 3.2.0 / 2017-02-28
## 3.2.0 / 2017-02-28
* fix(render): Toc rendering error, fixed [#106](https://github.com/QingWei-Li/docsify/issues/106)
* feat(search): Localization for no data tip, close [#103](https://github.com/QingWei-Li/docsify/issues/103)
* fix(fetch): load sidebar and navbar for parent path, fixed [#100](https://github.com/QingWei-Li/docsify/issues/100)
* feat(render) nameLink for each route, fixed [#99](https://github.com/QingWei-Li/docsify/issues/99)
# 3.1.2 / 2017-02-27
## 3.1.2 / 2017-02-27
* fix(search): dont search nameLink, fixed [#102](https://github.com/QingWei-Li/docsify/issues/102)
# 3.1.1 / 2017-02-24
## 3.1.1 / 2017-02-24
* fix(search): dont search nameLink, fixed [#102](https://github.com/QingWei-Li/docsify/issues/102)
* fix(render): custom cover background image
* fix(tpl): extra character, fixed [#101](https://github.com/QingWei-Li/docsify/issues/101)
# 3.1.0 / 2017-02-22
## 3.1.0 / 2017-02-22
* fix(search): incorrect anchor link, fixed [#90](https://github.com/QingWei-Li/docsify/issues/90)
* feat(emoji): add emoji plugin
# 3.0.5 / 2017-02-21
## 3.0.5 / 2017-02-21
* feat(pwa): add sw.js
* fix(layout.css): loading style
* fix(event): highlight sidebar when clicked, fixed [#86](https://github.com/QingWei-Li/docsify/issues/86)
* fix(gen-tree): cache toc list, fixed [#88](https://github.com/QingWei-Li/docsify/issues/88)
# 3.0.4 / 2017-02-20
## 3.0.4 / 2017-02-20
* fix(render): execute script
* fix(render): disable rendering sub list when loadSidebar is false
# 3.0.3 / 2017-02-19
## 3.0.3 / 2017-02-19
* fixed look of links in blockquote
* fix(scroll) highlight bug
# 3.0.2 / 2017-02-19
## 3.0.2 / 2017-02-19
* fix(search): add lazy input
* fix(compiler): link
# 3.0.1 / 2017-02-19
## 3.0.1 / 2017-02-19
* fix(route): empty alias
# 3.0.0 / 2017-02-19
## 3.0.0 / 2017-02-19
#### Breaking change
##### Breaking change
* Not support IE9
* The route becomes: `/#/page?id=slug`. The previous route will be redirected
#### Features
##### Features
* Faster rendering
* Clearer source code
+4
View File
@@ -27,6 +27,7 @@
- Multiple themes
- Useful plugin API
- Compatible with IE10+
- Support SSR ([example](https://github.com/QingWei-Li/docsify-ssr-demo))
## Quick start
@@ -64,6 +65,9 @@ These open-source projects are using docsify to generate their sites. Pull reque
| [Vudash](http://vudash.github.io/vudash/) | Powerful, Flexible, Open Source dashboards for anything |
| [Trilogy](http://trilogy.js.org) | No-hassle SQLite with a Promise-based, document store style API. |
| [Mybatis-Plus](http://mp.baomidou.com/) | An enhanced toolkit of Mybatis to simplify development |
| [JS MythBusters](https://mythbusters.js.org) | An optimization handbook from a high level point of view. |
| [hire-me](https://fvcproductions.github.io/hire-me) | A path to getting an awesome tech gig. |
| [vue-amap](https://elemefe.github.io/vue-amap/) | A Map Component Library Base on Vue 2.x and Gaode Map. |
## Similar projects
+39
View File
@@ -1,12 +1,51 @@
var serveStatic = require('serve-static')
var http = require('http')
var fs = require('fs')
var Renderer = require('./packages/docsify-server-renderer/build.js')
var renderer = new Renderer({
template: `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>docsify</title>
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<link rel="stylesheet" href="/themes/vue.css" title="vue">
</head>
<body>
<!--inject-app-->
<!--inject-config-->
<script src="/lib/docsify.js"></script>
</body>
</html>`,
config: {
name: 'docsify',
repo: 'qingwei-li/docsify',
basePath: 'https://docsify.js.org/',
loadNavbar: true,
loadSidebar: true,
subMaxLevel: 3,
auto2top: true,
alias: {
'/de-de/changelog': '/changelog',
'/zh-cn/changelog': '/changelog',
'/changelog': 'https://raw.githubusercontent.com/QingWei-Li/docsify/master/CHANGELOG'
}
},
path: './'
})
http.createServer(function (req, res) {
serveStatic('.')(req, res, function () {
// TEST SSR
// renderer.renderToString(req.url)
// .then(html => res.end(html))
res.writeHead(404, { 'Content-Type': 'text/html' })
res.end(fs.readFileSync('dev.html'))
})
}).listen(3000, '0.0.0.0')
console.log(`\nListening at http://0.0.0.0:3000\n`)
+30
View File
@@ -0,0 +1,30 @@
var rollup = require('rollup')
var buble = require('rollup-plugin-buble')
var async = require('rollup-plugin-async')
var isProd = process.argv[process.argv.length - 1] !== '--dev'
rollup
.rollup({
entry: 'packages/docsify-server-renderer/index.js',
plugins: [
async(),
buble({
transforms: {
generator: false
}
})
],
onwarn: function() {}
})
.then(function (bundle) {
var dest = 'packages/docsify-server-renderer/build.js'
console.log(dest)
bundle.write({
format: 'cjs',
dest: dest
})
})
.catch(function (err) {
console.error(err)
})
+43
View File
@@ -0,0 +1,43 @@
set -e
if [[ -z $1 ]]; then
echo "Enter new version: "
read VERSION
else
VERSION=$1
fi
read -p "Releasing $VERSION $RELEASE_TAG - are you sure? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo "Releasing $VERSION ..."
npm run test
# build
VERSION=$VERSION npm run build
# update packages
cd packages/docsify-server-renderer
npm version $VERSION
if [[ -z $RELEASE_TAG ]]; then
npm publish
else
npm publish --tag $RELEASE_TAG
fi
cd -
# commit
git add -A
git commit -m "[build] $VERSION $RELEASE_TAG"
npm version $VERSION --message "[release] $VERSION $RELEASE_TAG"
# publish
git push origin refs/tags/v$VERSION
git push
if [[ -z $RELEASE_TAG ]]; then
npm publish
else
npm publish --tag $RELEASE_TAG
fi
fi
+11 -1
View File
@@ -29,7 +29,17 @@
loadNavbar: true,
loadSidebar: true,
name: 'docsify',
subMaxLevel: 2
subMaxLevel: 2,
mergeNavbar: true,
formatUpdated: '{MM}/{DD} {HH}:{mm}',
routerMode: 'history',
plugins: [
function(hook) {
hook.beforeEach(function (html) {
return html += '\n> Last modified {docsify-updated}'
})
}
]
}
</script>
<script src="/lib/docsify.js"></script>
+1 -1
View File
@@ -1,6 +1,6 @@
![logo](_media/icon.svg)
# docsify <small>3.4</small>
# docsify <small>4.0</small>
> A magical documentation site generator.
+4 -4
View File
@@ -1,4 +1,4 @@
- :uk:
- [:cn: 中文](/zh-cn/)
- [:de: Deutsch](/de-de/)
- [:uk: English](/)
- Translations
- [:cn: 中文](/zh-cn/)
- [:de: Deutsch](/de-de/)
- [:uk: English](/)
+1
View File
@@ -18,5 +18,6 @@
- [Vue compatibility](vue.md)
- [CDN](cdn.md)
- [Offline Mode(PWA)](pwa.md)
- [Server-client renderer(SSR)](ssr.md)
- [Changelog](changelog.md)
+4 -1
View File
@@ -44,4 +44,7 @@ Alternatively, use [compressed files](#compressed-files).
## Other CDN
[jsDelivr](http://www.jsdelivr.com/projects/docsify) is available.
- http://www.bootcdn.cn/docsify
- http://www.jsdelivr.com/projects/docsify
- https://cdnjs.com/libraries/docsify
+42
View File
@@ -305,3 +305,45 @@ window.$docsify = {
noEmoji: true
}
```
## merge-navbar
Navbar will be merged with the sidebar on smaller screens.
```js
window.$docsify = {
mergeNavbar: true
}
```
## format-updated
We can display the file update date through **{docsify-updated<span>}</span>** variable. And format it by `formatUpdated`.
See https://github.com/lukeed/tinydate#patterns
```js
window.$docsify = {
formatUpdated: '{MM}/{DD} {HH}:{mm}',
formatUpdated: function (time) {
// ...
return time
}
}
```
## external-link-target
Currently it defaults to _blank, would be nice if configurable:
```js
window.$docsify = {
externalLinkTarget: '_self' // default: '_blank'
}
```
## router-mode
```js
window.$docsify = {
routerMode: 'history' // default: 'hash'
}
```
-4
View File
@@ -1,4 +0,0 @@
- :de:
- [:cn: 中文](/zh-cn/)
- [:de: Deutsch](/de-de/)
- [:uk: English](/)
+1
View File
@@ -18,5 +18,6 @@
- [Vue Kompatibilität](de-de/vue.md)
- [CDN](de-de/cdn.md)
- [Offline Modus (PWA)](de-de/pwa.md)
- [Server-client renderer (SSR)](de-de/ssr.md)
- [Changelog](de-de/changelog.md)
+3 -1
View File
@@ -44,4 +44,6 @@ Alternativ kannst du auch die [komprimierten Dateien](#komprimierte-dateien) ver
## Andere CDN
[jsDelivr](http://www.jsdelivr.com/projects/docsify) ist auch verfügbar.
- http://www.bootcdn.cn/docsify
- http://www.jsdelivr.com/projects/docsify
- https://cdnjs.com/libraries/docsify
+35
View File
@@ -305,3 +305,38 @@ window.$docsify = {
noEmoji: true
}
```
## merge-navbar
Navbar will be merged with the sidebar on smaller screens.
```js
window.$docsify = {
mergeNavbar: true
}
```
## format-updated
We can display the file update date through **{docsify-updated<span>}</span>** variable. And format it by `formatUpdated`.
See https://github.com/lukeed/tinydate#patterns
```js
window.$docsify = {
formatUpdated: '{MM}/{DD} {HH}:{mm}',
formatUpdated: function (time) {
// ...
return time
}
}
```
## external-link-target
Currently it defaults to _blank, would be nice if configurable:
```js
window.$docsify = {
externalLinkTarget: '_self' // default: '_blank'
}
```
+124
View File
@@ -0,0 +1,124 @@
# Server client renderer
See https://docsify.now.sh
## Why SSR?
- Better SEO
- Feeling cool
## Quick start
Install `now` and `docsify-cli` in your project.
```bash
npm i now -g
npm i docsify-cli -D
```
Edit `package.json`. If the documentation in `./docs` subdirectory.
```json
{
"name": "my-project",
"scripts": {
"start": "docsify start ."
},
"files": [
"docs"
],
"docsify": {
"config": {
"basePath": "/docs/",
"loadSidebar": true,
"loadNavbar": true,
"coverpage": true,
"name": "docsify"
}
}
}
```
Remove `index.html`
!> The `basePath` just like webpack `publicPath`. You should config it if your docs is in the subdirectory.
We can preview in the local to see if it works.
```bash
npm start
# open http://localhost:4000
```
Publish it!
```bash
now -p
```
Now, You have a support for SSR the docs site.
## Custom template
You can provide a templte for entire page's HTML. such as
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>docsify</title>
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<link rel="stylesheet" href="//unpkg.com/docsify/themes/vue.css" title="vue">
</head>
<body>
<!--inject-app-->
<!--inject-config-->
</body>
<script src="//unpkg.com/docsify/lib/docsify.js"></script>
<script src="//unpkg.com/docsify/lib/plugins/search.js"></script>
<script src="//unpkg.com/prismjs/components/prism-bash.min.js"></script>
<script src="//unpkg.com/prismjs/components/prism-markdown.min.js"></script>
<script src="//unpkg.com/prismjs/components/prism-nginx.min.js"></script>
</html>
```
The template should contain these comments for rendered app content.
- `<!--inject-app-->`
- `<!--inject-config-->`
## Configuration
You can configure it in a special config file, or `package.json`.
```js
module.exports = {
template: './ssr.html',
config: {
// docsify config
}
}
```
## Deploy for your VPS
You can run `docsify start` directly on your Node server, or write your own server app with `docsify-server-renderer`.
```js
var Renderer = require('docsify-server-renderer')
var readFileSync = require('fs').readFileSync
// init
var renderer = new Renderer({
template: readFileSync('./docs/index.template.html', 'utf-8').,
config: {
name: 'docsify',
repo: 'qingwei-li/docsify'
}
})
renderer.renderToString(url)
.then(html => {})
.catch(err => {})
```
+10 -1
View File
@@ -32,7 +32,9 @@
executeScript: true,
loadSidebar: true,
loadNavbar: true,
mergeNavbar: true,
maxLevel: 4,
subMaxLevel: 2,
name: 'docsify',
search: {
noData: {
@@ -47,7 +49,14 @@
'/': 'Search'
}
},
subMaxLevel: 2
formatUpdated: '{MM}/{DD} {HH}:{mm}',
plugins: [
function(hook) {
hook.beforeEach(function (html) {
return html += '\n> Last modified {docsify-updated}'
})
}
]
}
</script>
<script src="//unpkg.com/docsify/lib/docsify.min.js"></script>
+6 -6
View File
@@ -6,12 +6,12 @@ For example, the directory structure is as follows:
```text
.
── docs
| ── README.md
| ── guide.md
| └── zh-cn
| ──README.md
| └──guide.md
── docs
── README.md
── guide.md
└── zh-cn
── README.md
└── guide.md
```
Matching routes
+123
View File
@@ -0,0 +1,123 @@
# Server client renderer
See https://docsify.now.sh
## Why SSR?
- Better SEO
- Feeling cool
## Quick start
Install `now` and `docsify-cli` in your project.
```bash
npm i now -g
npm i docsify-cli -D
```
Edit `package.json`. If the documentation in `./docs` subdirectory.
```json
{
"name": "my-project",
"scripts": {
"start": "docsify start ."
},
"files": [
"docs"
],
"docsify": {
"config": {
"basePath": "/docs/",
"loadSidebar": true,
"loadNavbar": true,
"coverpage": true,
"name": "docsify"
}
}
}
```
Remove `index.html`
!> The `basePath` just like webpack `publicPath`. You should config it if your docs is in the subdirectory.
We can preview in the local to see if it works.
```bash
npm start
# open http://localhost:4000
```
Publish it!
```bash
now -p
```
Now, You have a support for SSR the docs site.
## Custom template
You can provide a templte for entire page's HTML. such as
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>docsify</title>
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<link rel="stylesheet" href="//unpkg.com/docsify/themes/vue.css" title="vue">
</head>
<body>
<!--inject-app-->
<!--inject-config-->
</body>
<script src="//unpkg.com/docsify/lib/docsify.js"></script>
<script src="//unpkg.com/docsify/lib/plugins/search.js"></script>
<script src="//unpkg.com/prismjs/components/prism-bash.min.js"></script>
<script src="//unpkg.com/prismjs/components/prism-markdown.min.js"></script>
<script src="//unpkg.com/prismjs/components/prism-nginx.min.js"></script>
</html>
```
The template should contain these comments for rendered app content.
- `<!--inject-app-->`
- `<!--inject-config-->`
## Configuration
You can configure it in a special config file, or `package.json`.
```js
module.exports = {
template: './ssr.html',
config: {
// docsify config
}
}
```
## Deploy for your VPS
You can run `docsify start` directly on your Node server, or write your own server app with `docsify-server-renderer`.
```js
var Renderer = require('docsify-server-renderer')
var readFileSync = require('fs').readFileSync
// init
var renderer = new Renderer({
template: readFileSync('./docs/index.template.html', 'utf-8').,
config: {
name: 'docsify',
repo: 'qingwei-li/docsify'
}
})
renderer.renderToString(url)
.then(html => {})
.catch(err => {})
```
-4
View File
@@ -1,4 +0,0 @@
- :cn:
- [:cn: 中文](/zh-cn/)
- [:de: Deutsch](/de-de/)
- [:uk: English](/)
+1
View File
@@ -18,5 +18,6 @@
- [兼容 Vue](zh-cn/vue.md)
- [CDN](zh-cn/cdn.md)
- [离线模式(PWA)](zh-cn/pwa.md)
- [服务端渲染 (SSR)](zh-cn/ssr.md)
- [Changelog](zh-cn/changelog.md)
+3 -2
View File
@@ -44,5 +44,6 @@ JS 的压缩文件是原有文件路径的基础上加 `.min`后缀
## 其他 CDN
[jsDelivr](http://www.jsdelivr.com/projects/docsify) 也是可用的,具体用法参考其文档。
- http://www.bootcdn.cn/docsify
- http://www.jsdelivr.com/projects/docsify
- https://cdnjs.com/libraries/docsify
+35
View File
@@ -315,3 +315,38 @@ window.$docsify = {
noEmoji: true
}
```
## merge-navbar
小屏设备下合并导航栏到侧边栏。
```js
window.$docsify = {
mergeNavbar: true
}
```
## format-updated
我们可以显示文档更新日期通过 **{docsify-updated<span>}</span>** 变量. 并且格式化日期通过 `formatUpdated`.
参考 https://github.com/lukeed/tinydate#patterns
```js
window.$docsify = {
formatUpdated: '{MM}/{DD} {HH}:{mm}',
formatUpdated: function (time) {
// ...
return time
}
}
```
## external-link-target
Currently it defaults to _blank, would be nice if configurable:
```js
window.$docsify = {
externalLinkTarget: '_self' // default: '_blank'
}
```
+124
View File
@@ -0,0 +1,124 @@
# Server client renderer
See https://docsify.now.sh
## Why SSR?
- Better SEO
- Feeling cool
## Quick start
Install `now` and `docsify-cli` in your project.
```bash
npm i now -g
npm i docsify-cli -D
```
2. Edit `package.json`. If the documentation in `./docs` subdirectory.
```json
{
"name": "my-project",
"scripts": {
"start": "docsify start ."
},
"files": [
"docs"
],
"docsify": {
"config": {
"basePath": "/docs/",
"loadSidebar": true,
"loadNavbar": true,
"coverpage": true,
"name": "docsify"
}
}
}
```
Remove `index.html`
!> The `basePath` just like webpack `publicPath`. You should config it if your docs is in the subdirectory.
We can preview in the local to see if it works.
```bash
npm start
# open http://localhost:4000
```
Publish it!
```bash
now -p
```
Now, You have a support for SSR the docs site.
## Custom template
You can provide a templte for entire page's HTML. such as
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>docsify</title>
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<link rel="stylesheet" href="//unpkg.com/docsify/themes/vue.css" title="vue">
</head>
<body>
<!--inject-app-->
<!--inject-config-->
</body>
<script src="//unpkg.com/docsify/lib/docsify.js"></script>
<script src="//unpkg.com/docsify/lib/plugins/search.js"></script>
<script src="//unpkg.com/prismjs/components/prism-bash.min.js"></script>
<script src="//unpkg.com/prismjs/components/prism-markdown.min.js"></script>
<script src="//unpkg.com/prismjs/components/prism-nginx.min.js"></script>
</html>
```
The template should contain these comments for rendered app content.
- `<!--inject-app-->`
- `<!--inject-config-->`
## Configuration
You can configure it in a special config file, or `package.json`.
```js
module.exports = {
template: './ssr.html',
config: {
// docsify config
}
}
```
## Deploy for your VPS
You can run `docsify start` directly on your Node server, or write your own server app with `docsify-server-renderer`.
```js
var Renderer = require('docsify-server-renderer')
var readFileSync = require('fs').readFileSync
// init
var renderer = new Renderer({
template: readFileSync('./docs/index.template.html', 'utf-8').,
config: {
name: 'docsify',
repo: 'qingwei-li/docsify'
}
})
renderer.renderToString(url)
.then(html => {})
.catch(err => {})
```
+793 -549
View File
File diff suppressed because it is too large Load Diff
+2 -2
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+13 -7
View File
@@ -4,15 +4,21 @@ this.D = this.D || {};
function handleExternalScript () {
var container = Docsify.dom.getNode('#main');
var script = Docsify.dom.find(container, 'script');
var scripts = Docsify.dom.findAll(container, 'script');
if (script && script.src) {
var newScript = document.createElement('script');['src', 'async', 'defer'].forEach(function (attribute) {
newScript[attribute] = script[attribute];
});
for (var i = scripts.length; i--;) {
var script = scripts[i];
script.parentNode.insertBefore(newScript, script);
script.parentNode.removeChild(script);
if (script && script.src) {
var newScript = document.createElement('script');
Array.prototype.slice.call(script.attributes).forEach(function (attribute) {
newScript[attribute.name] = attribute.value;
});
script.parentNode.insertBefore(newScript, script);
script.parentNode.removeChild(script);
}
}
}
+1 -1
View File
@@ -1 +1 @@
this.D=this.D||{},function(){"use strict";function i(){var i=Docsify.dom.getNode("#main"),n=Docsify.dom.find(i,"script");if(n&&n.src){var o=document.createElement("script");["src","async","defer"].forEach(function(i){o[i]=n[i]}),n.parentNode.insertBefore(o,n),n.parentNode.removeChild(n)}}var n=function(n){n.doneEach(i)};window.$docsify.plugins=[].concat(n,window.$docsify.plugins)}();
this.D=this.D||{},function(){"use strict";function e(){for(var e=Docsify.dom.getNode("#main"),i=Docsify.dom.findAll(e,"script"),o=i.length;o--;){var t=i[o];if(t&&t.src){var n=document.createElement("script");Array.prototype.slice.call(t.attributes).forEach(function(e){n[e.name]=e.value}),t.parentNode.insertBefore(n,t),t.parentNode.removeChild(t)}}}var i=function(i){i.doneEach(e)};window.$docsify.plugins=[].concat(i,window.$docsify.plugins)}();
+1 -1
View File
File diff suppressed because one or more lines are too long
+14 -10
View File
@@ -11,24 +11,28 @@ function appendScript () {
}
function init (id) {
if (!window.ga) {
var ga = window.ga;
if (!ga) {
appendScript();
window.ga = window.ga || function () {
(window.ga.q = window.ga.q || []).push(arguments);
ga = ga || function () {
(ga.q = ga.q || []).push(arguments);
};
window.ga.l = Number(new Date());
window.ga('create', id, 'auto');
ga.l = Number(new Date());
ga('create', id, 'auto');
}
return ga
}
function collect () {
init(window.$docsify.ga);
window.ga('set', 'page', location.href);
window.ga('send', 'pageview');
var ga = init($docsify.ga);
ga('set', 'page', location.hash);
ga('send', 'pageview');
}
var install = function (hook) {
if (!window.$docsify.ga) {
if (!$docsify.ga) {
console.error('[Docsify] ga is required.');
return
}
@@ -36,6 +40,6 @@ var install = function (hook) {
hook.beforeEach(collect);
};
window.$docsify.plugins = [].concat(install, window.$docsify.plugins);
$docsify.plugins = [].concat(install, $docsify.plugins);
}());
+1 -1
View File
@@ -1 +1 @@
this.D=this.D||{},function(){"use strict";function n(){var n=document.createElement("script");n.async=!0,n.src="https://www.google-analytics.com/analytics.js",document.body.appendChild(n)}function o(o){window.ga||(n(),window.ga=window.ga||function(){(window.ga.q=window.ga.q||[]).push(arguments)},window.ga.l=Number(new Date),window.ga("create",o,"auto"))}function i(){o(window.$docsify.ga),window.ga("set","page",location.href),window.ga("send","pageview")}var w=function(n){return window.$docsify.ga?void n.beforeEach(i):void console.error("[Docsify] ga is required.")};window.$docsify.plugins=[].concat(w,window.$docsify.plugins)}();
this.D=this.D||{},function(){"use strict";function n(){var n=document.createElement("script");n.async=!0,n.src="https://www.google-analytics.com/analytics.js",document.body.appendChild(n)}function c(c){var e=window.ga;return e||(n(),e=e||function(){(e.q=e.q||[]).push(arguments)},e.l=Number(new Date),e("create",c,"auto")),e}function e(){var n=c($docsify.ga);n("set","page",location.hash),n("send","pageview")}var i=function(n){if(!$docsify.ga)return void console.error("[Docsify] ga is required.");n.beforeEach(e)};$docsify.plugins=[].concat(i,$docsify.plugins)}();
+53 -47
View File
@@ -18,18 +18,18 @@ function escapeHtml (string) {
return String(string).replace(/[&<>"'\/]/g, function (s) { return entityMap[s]; })
}
function getAllPaths () {
function getAllPaths (router) {
var paths = [];
helper.dom.findAll('a:not([data-nosearch])')
.map(function (node) {
var href = node.href;
var originHref = node.getAttribute('href');
var path = helper.route.parse(href).path;
var path = router.parse(href).path;
if (path &&
paths.indexOf(path) === -1 &&
!helper.route.isAbsolutePath(originHref)) {
!Docsify.util.isAbsolutePath(originHref)) {
paths.push(path);
}
});
@@ -42,18 +42,17 @@ function saveData (maxAge) {
localStorage.setItem('docsify.search.index', JSON.stringify(INDEXS));
}
function genIndex (path, content) {
function genIndex (path, content, router) {
if ( content === void 0 ) content = '';
var tokens = window.marked.lexer(content);
var slugify = window.Docsify.slugify;
var toURL = Docsify.route.toURL;
var index = {};
var slug;
tokens.forEach(function (token) {
if (token.type === 'heading' && token.depth <= 2) {
slug = toURL(path, { id: slugify(token.text) });
slug = router.toURL(path, { id: slugify(token.text) });
index[slug] = { slug: slug, title: token.text, body: '' };
} else {
if (!slug) { return }
@@ -153,7 +152,7 @@ function init$1 (config, vm) {
return
}
var paths = isAuto ? getAllPaths() : config.paths;
var paths = isAuto ? getAllPaths(vm.router) : config.paths;
var len = paths.length;
var count = 0;
@@ -161,73 +160,78 @@ function init$1 (config, vm) {
if (INDEXS[path]) { return count++ }
helper
.get(vm.$getFile(path))
.get(vm.router.getFile(path))
.then(function (result) {
INDEXS[path] = genIndex(path, result);
INDEXS[path] = genIndex(path, result, vm.router);
len === ++count && saveData(config.maxAge);
});
});
}
var dom;
var NO_DATA_TEXT = '';
function style () {
var code = "\n.sidebar {\n padding-top: 0;\n}\n\n.search {\n margin-bottom: 20px;\n padding: 6px;\n border-bottom: 1px solid #eee;\n}\n\n.search .results-panel {\n display: none;\n}\n\n.search .results-panel.show {\n display: block;\n}\n\n.search input {\n outline: none;\n border: none;\n width: 100%;\n padding: 7px;\n line-height: 22px;\n font-size: 14px;\n -webkit-appearance: none;\n -moz-appearance: none;\n appearance: none;\n}\n\n.search h2 {\n font-size: 17px;\n margin: 10px 0;\n}\n\n.search a {\n text-decoration: none;\n color: inherit;\n}\n\n.search .matching-post {\n border-bottom: 1px solid #eee;\n}\n\n.search .matching-post:last-child {\n border-bottom: 0;\n}\n\n.search p {\n font-size: 14px;\n overflow: hidden;\n text-overflow: ellipsis;\n display: -webkit-box;\n -webkit-line-clamp: 2;\n -webkit-box-orient: vertical;\n}\n\n.search p.empty {\n text-align: center;\n}";
var style = dom.create('style', code);
dom.appendTo(dom.head, style);
var style = Docsify.dom.create('style', code);
Docsify.dom.appendTo(Docsify.dom.head, style);
}
function tpl (opts) {
function tpl (opts, defaultValue) {
if ( defaultValue === void 0 ) defaultValue = '';
var html =
"<input type=\"search\" />" +
"<input type=\"search\" value=\"" + defaultValue + "\" />" +
'<div class="results-panel"></div>' +
'</div>';
var el = dom.create('div', html);
var aside = dom.find('aside');
var el = Docsify.dom.create('div', html);
var aside = Docsify.dom.find('aside');
dom.toggleClass(el, 'search');
dom.before(aside, el);
Docsify.dom.toggleClass(el, 'search');
Docsify.dom.before(aside, el);
}
function doSearch (value) {
var $search = Docsify.dom.find('div.search');
var $panel = Docsify.dom.find($search, '.results-panel');
if (!value) {
$panel.classList.remove('show');
$panel.innerHTML = '';
return
}
var matchs = search(value);
var html = '';
matchs.forEach(function (post) {
html += "<div class=\"matching-post\">\n<h2><a href=\"" + (post.url) + "\">" + (post.title) + "</a></h2>\n<p>" + (post.content) + "</p>\n</div>";
});
$panel.classList.add('show');
$panel.innerHTML = html || ("<p class=\"empty\">" + NO_DATA_TEXT + "</p>");
}
function bindEvents () {
var $search = dom.find('div.search');
var $input = dom.find($search, 'input');
var $panel = dom.find($search, '.results-panel');
var doSearch = function (value) {
if (!value) {
$panel.classList.remove('show');
$panel.innerHTML = '';
return
}
var matchs = search(value);
var html = '';
matchs.forEach(function (post) {
html += "<div class=\"matching-post\">\n <h2><a href=\"" + (post.url) + "\">" + (post.title) + "</a></h2>\n <p>" + (post.content) + "</p>\n</div>";
});
$panel.classList.add('show');
$panel.innerHTML = html || ("<p class=\"empty\">" + NO_DATA_TEXT + "</p>");
};
var $search = Docsify.dom.find('div.search');
var $input = Docsify.dom.find($search, 'input');
var timeId;
// Prevent to Fold sidebar
dom.on($search, 'click',
Docsify.dom.on($search, 'click',
function (e) { return e.target.tagName !== 'A' && e.stopPropagation(); });
dom.on($input, 'input', function (e) {
Docsify.dom.on($input, 'input', function (e) {
clearTimeout(timeId);
timeId = setTimeout(function (_) { return doSearch(e.target.value.trim()); }, 100);
});
}
function updatePlaceholder (text, path) {
var $input = dom.getNode('.search input[type="search"]');
var $input = Docsify.dom.getNode('.search input[type="search"]');
if (!$input) { return }
if (typeof text === 'string') {
$input.placeholder = text;
} else {
var match = Object.keys(text).find(function (key) { return path.indexOf(key) > -1; });
var match = Object.keys(text).filter(function (key) { return path.indexOf(key) > -1; })[0];
$input.placeholder = text[match];
}
}
@@ -236,16 +240,18 @@ function updateNoData (text, path) {
if (typeof text === 'string') {
NO_DATA_TEXT = text;
} else {
var match = Object.keys(text).find(function (key) { return path.indexOf(key) > -1; });
var match = Object.keys(text).filter(function (key) { return path.indexOf(key) > -1; })[0];
NO_DATA_TEXT = text[match];
}
}
function init$$1 (opts) {
dom = Docsify.dom;
function init$$1 (opts, vm) {
var keywords = vm.router.parse().query.s;
style();
tpl(opts);
tpl(opts, keywords);
bindEvents();
keywords && setTimeout(function (_) { return doSearch(keywords); }, 500);
}
function update (opts, vm) {
@@ -276,7 +282,7 @@ var install = function (hook, vm) {
var isAuto = CONFIG.paths === 'auto';
hook.mounted(function (_) {
init$$1(CONFIG);
init$$1(CONFIG, vm);
!isAuto && init$1(CONFIG, vm);
});
hook.doneEach(function (_) {
@@ -285,6 +291,6 @@ var install = function (hook, vm) {
});
};
window.$docsify.plugins = [].concat(install, window.$docsify.plugins);
$docsify.plugins = [].concat(install, $docsify.plugins);
}());
+1 -1
View File
@@ -1 +1 @@
this.D=this.D||{},function(){"use strict";function n(n){var e={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;","/":"&#x2F;"};return String(n).replace(/[&<>"'\/]/g,function(n){return e[n]})}function e(){var n=[];return d.dom.findAll("a:not([data-nosearch])").map(function(e){var t=e.href,a=e.getAttribute("href"),o=d.route.parse(t).path;o&&n.indexOf(o)===-1&&!d.route.isAbsolutePath(a)&&n.push(o)}),n}function t(n){localStorage.setItem("docsify.search.expires",Date.now()+n),localStorage.setItem("docsify.search.index",JSON.stringify(g))}function a(n,e){void 0===e&&(e="");var t,a=window.marked.lexer(e),o=window.Docsify.slugify,r=Docsify.route.toURL,i={};return a.forEach(function(e){if("heading"===e.type&&e.depth<=2)t=r(n,{id:o(e.text)}),i[t]={slug:t,title:e.text,body:""};else{if(!t)return;i[t]?i[t].body?i[t].body+="\n"+(e.text||""):i[t].body=e.text:i[t]={slug:t,title:"",body:""}}}),o.clear(),i}function o(e){var t=[],a=[];Object.keys(g).forEach(function(n){a=a.concat(Object.keys(g[n]).map(function(e){return g[n][e]}))}),e=[].concat(e,e.trim().split(/[\s\-\\\\/]+/));for(var o=function(o){var r=a[o],i=!1,s="",c=r.title&&r.title.trim(),l=r.body&&r.body.trim(),p=r.slug||"";if(c&&l&&(e.forEach(function(e,t){var a=new RegExp(e,"gi"),o=-1,r=-1;if(o=c&&c.search(a),r=l&&l.search(a),o<0&&r<0)i=!1;else{i=!0,r<0&&(r=0);var p=0,u=0;p=r<11?0:r-10,u=0===p?70:r+e.length+60,u>l.length&&(u=l.length);var f="..."+n(l).substring(p,u).replace(a,'<em class="search-keyword">'+e+"</em>")+"...";s+=f}}),i)){var u={title:n(c),content:s,url:p};t.push(u)}},r=0;r<a.length;r++)o(r);return t}function r(n,o){d=Docsify;var r="auto"===n.paths,i=localStorage.getItem("docsify.search.expires")<Date.now();if(g=JSON.parse(localStorage.getItem("docsify.search.index")),i)g={};else if(!r)return;var s=r?e():n.paths,c=s.length,l=0;s.forEach(function(e){return g[e]?l++:void d.get(o.$getFile(e)).then(function(o){g[e]=a(e,o),c===++l&&t(n.maxAge)})})}function i(){var n="\n.sidebar {\n padding-top: 0;\n}\n\n.search {\n margin-bottom: 20px;\n padding: 6px;\n border-bottom: 1px solid #eee;\n}\n\n.search .results-panel {\n display: none;\n}\n\n.search .results-panel.show {\n display: block;\n}\n\n.search input {\n outline: none;\n border: none;\n width: 100%;\n padding: 7px;\n line-height: 22px;\n font-size: 14px;\n -webkit-appearance: none;\n -moz-appearance: none;\n appearance: none;\n}\n\n.search h2 {\n font-size: 17px;\n margin: 10px 0;\n}\n\n.search a {\n text-decoration: none;\n color: inherit;\n}\n\n.search .matching-post {\n border-bottom: 1px solid #eee;\n}\n\n.search .matching-post:last-child {\n border-bottom: 0;\n}\n\n.search p {\n font-size: 14px;\n overflow: hidden;\n text-overflow: ellipsis;\n display: -webkit-box;\n -webkit-line-clamp: 2;\n -webkit-box-orient: vertical;\n}\n\n.search p.empty {\n text-align: center;\n}",e=h.create("style",n);h.appendTo(h.head,e)}function s(n){var e='<input type="search" /><div class="results-panel"></div></div>',t=h.create("div",e),a=h.find("aside");h.toggleClass(t,"search"),h.before(a,t)}function c(){var n,e=h.find("div.search"),t=h.find(e,"input"),a=h.find(e,".results-panel"),r=function(n){if(!n)return a.classList.remove("show"),void(a.innerHTML="");var e=o(n),t="";e.forEach(function(n){t+='<div class="matching-post">\n <h2><a href="'+n.url+'">'+n.title+"</a></h2>\n <p>"+n.content+"</p>\n</div>"}),a.classList.add("show"),a.innerHTML=t||'<p class="empty">'+y+"</p>"};h.on(e,"click",function(n){return"A"!==n.target.tagName&&n.stopPropagation()}),h.on(t,"input",function(e){clearTimeout(n),n=setTimeout(function(n){return r(e.target.value.trim())},100)})}function l(n,e){var t=h.getNode('.search input[type="search"]');if("string"==typeof n)t.placeholder=n;else{var a=Object.keys(n).find(function(n){return e.indexOf(n)>-1});t.placeholder=n[a]}}function p(n,e){if("string"==typeof n)y=n;else{var t=Object.keys(n).find(function(n){return e.indexOf(n)>-1});y=n[t]}}function u(n){h=Docsify.dom,i(),s(n),c()}function f(n,e){l(n.placeholder,e.route.path),p(n.noData,e.route.path)}var d,h,g={},y="",m={placeholder:"Type to search",noData:"No Results!",paths:"auto",maxAge:864e5},v=function(n,e){var t=Docsify.util,a=e.config.search||m;Array.isArray(a)?m.paths=a:"object"==typeof a&&(m.paths=Array.isArray(a.paths)?a.paths:"auto",m.maxAge=t.isPrimitive(a.maxAge)?a.maxAge:m.maxAge,m.placeholder=a.placeholder||m.placeholder,m.noData=a.noData||m.noData);var o="auto"===m.paths;n.mounted(function(n){u(m),!o&&r(m,e)}),n.doneEach(function(n){f(m,e),o&&r(m,e)})};window.$docsify.plugins=[].concat(v,window.$docsify.plugins)}();
this.D=this.D||{},function(){"use strict";function e(e){var n={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;","/":"&#x2F;"};return String(e).replace(/[&<>"'\/]/g,function(e){return n[e]})}function n(e){var n=[];return h.dom.findAll("a:not([data-nosearch])").map(function(t){var o=t.href,i=t.getAttribute("href"),r=e.parse(o).path;r&&-1===n.indexOf(r)&&!Docsify.util.isAbsolutePath(i)&&n.push(r)}),n}function t(e){localStorage.setItem("docsify.search.expires",Date.now()+e),localStorage.setItem("docsify.search.index",JSON.stringify(y))}function o(e,n,t){void 0===n&&(n="");var o,i=window.marked.lexer(n),r=window.Docsify.slugify,a={};return i.forEach(function(n){if("heading"===n.type&&n.depth<=2)o=t.toURL(e,{id:r(n.text)}),a[o]={slug:o,title:n.text,body:""};else{if(!o)return;a[o]?a[o].body?a[o].body+="\n"+(n.text||""):a[o].body=n.text:a[o]={slug:o,title:"",body:""}}}),r.clear(),a}function i(n){var t=[],o=[];Object.keys(y).forEach(function(e){o=o.concat(Object.keys(y[e]).map(function(n){return y[e][n]}))}),n=[].concat(n,n.trim().split(/[\s\-\\\\/]+/));for(var i=0;i<o.length;i++)!function(i){var r=o[i],a=!1,s="",c=r.title&&r.title.trim(),f=r.body&&r.body.trim(),l=r.slug||"";if(c&&f&&(n.forEach(function(n,t){var o=new RegExp(n,"gi"),i=-1,r=-1;if(i=c&&c.search(o),r=f&&f.search(o),i<0&&r<0)a=!1;else{a=!0,r<0&&(r=0);var l=0,d=0;l=r<11?0:r-10,d=0===l?70:r+n.length+60,d>f.length&&(d=f.length);var u="..."+e(f).substring(l,d).replace(o,'<em class="search-keyword">'+n+"</em>")+"...";s+=u}}),a)){var d={title:e(c),content:s,url:l};t.push(d)}}(i);return t}function r(e,i){h=Docsify;var r="auto"===e.paths,a=localStorage.getItem("docsify.search.expires")<Date.now();if(y=JSON.parse(localStorage.getItem("docsify.search.index")),a)y={};else if(!r)return;var s=r?n(i.router):e.paths,c=s.length,f=0;s.forEach(function(n){if(y[n])return f++;h.get(i.router.getFile(n)).then(function(r){y[n]=o(n,r,i.router),c===++f&&t(e.maxAge)})})}function a(){var e=Docsify.dom.create("style","\n.sidebar {\n padding-top: 0;\n}\n\n.search {\n margin-bottom: 20px;\n padding: 6px;\n border-bottom: 1px solid #eee;\n}\n\n.search .results-panel {\n display: none;\n}\n\n.search .results-panel.show {\n display: block;\n}\n\n.search input {\n outline: none;\n border: none;\n width: 100%;\n padding: 7px;\n line-height: 22px;\n font-size: 14px;\n -webkit-appearance: none;\n -moz-appearance: none;\n appearance: none;\n}\n\n.search h2 {\n font-size: 17px;\n margin: 10px 0;\n}\n\n.search a {\n text-decoration: none;\n color: inherit;\n}\n\n.search .matching-post {\n border-bottom: 1px solid #eee;\n}\n\n.search .matching-post:last-child {\n border-bottom: 0;\n}\n\n.search p {\n font-size: 14px;\n overflow: hidden;\n text-overflow: ellipsis;\n display: -webkit-box;\n -webkit-line-clamp: 2;\n -webkit-box-orient: vertical;\n}\n\n.search p.empty {\n text-align: center;\n}");Docsify.dom.appendTo(Docsify.dom.head,e)}function s(e,n){void 0===n&&(n="");var t='<input type="search" value="'+n+'" /><div class="results-panel"></div></div>',o=Docsify.dom.create("div",t),i=Docsify.dom.find("aside");Docsify.dom.toggleClass(o,"search"),Docsify.dom.before(i,o)}function c(e){var n=Docsify.dom.find("div.search"),t=Docsify.dom.find(n,".results-panel");if(!e)return t.classList.remove("show"),void(t.innerHTML="");var o=i(e),r="";o.forEach(function(e){r+='<div class="matching-post">\n<h2><a href="'+e.url+'">'+e.title+"</a></h2>\n<p>"+e.content+"</p>\n</div>"}),t.classList.add("show"),t.innerHTML=r||'<p class="empty">'+m+"</p>"}function f(){var e,n=Docsify.dom.find("div.search"),t=Docsify.dom.find(n,"input");Docsify.dom.on(n,"click",function(e){return"A"!==e.target.tagName&&e.stopPropagation()}),Docsify.dom.on(t,"input",function(n){clearTimeout(e),e=setTimeout(function(e){return c(n.target.value.trim())},100)})}function l(e,n){var t=Docsify.dom.getNode('.search input[type="search"]');if(t)if("string"==typeof e)t.placeholder=e;else{var o=Object.keys(e).filter(function(e){return n.indexOf(e)>-1})[0];t.placeholder=e[o]}}function d(e,n){if("string"==typeof e)m=e;else{var t=Object.keys(e).filter(function(e){return n.indexOf(e)>-1})[0];m=e[t]}}function u(e,n){var t=n.router.parse().query.s;a(),s(e,t),f(),t&&setTimeout(function(e){return c(t)},500)}function p(e,n){l(e.placeholder,n.route.path),d(e.noData,n.route.path)}var h,y={},m="",g={placeholder:"Type to search",noData:"No Results!",paths:"auto",maxAge:864e5},v=function(e,n){var t=Docsify.util,o=n.config.search||g;Array.isArray(o)?g.paths=o:"object"==typeof o&&(g.paths=Array.isArray(o.paths)?o.paths:"auto",g.maxAge=t.isPrimitive(o.maxAge)?o.maxAge:g.maxAge,g.placeholder=o.placeholder||g.placeholder,g.noData=o.noData||g.noData);var i="auto"===g.paths;e.mounted(function(e){u(g,n),!i&&r(g,n)}),e.doneEach(function(e){p(g,n),i&&r(g,n)})};$docsify.plugins=[].concat(v,$docsify.plugins)}();
+1 -1
View File
@@ -1 +1 @@
this.D=this.D||{},function(){"use strict";function t(t,e){return e={exports:{}},t(e,e.exports),e.exports}function e(t){var e,n=Docsify.dom;n.appendTo(n.head,n.create("style",i)),t.doneEach(function(t){var i=n.findAll("img:not(.emoji)");Array.isArray(e)&&e.length&&(e.forEach(function(t){return t()}),e=[]),e=i.map(o)})}var n="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},o=t(function(t,e){!function(e,n){t.exports=n()}(n,function(){function t(){g===-1&&(g=window.pageYOffset);var t=Math.abs(g-window.pageYOffset);t>=40&&a()}function e(t){27===t.keyCode&&a()}function n(t){var e=t.touches[0];null!==e&&(y=e.pageY,t.target.addEventListener("touchmove",o))}function o(t){var e=t.touches[0];null!==e&&Math.abs(e.pageY-y)>10&&(a(),t.target.removeEventListener("touchmove",o))}function i(){a()}function r(){document.addEventListener("scroll",t),document.addEventListener("keyup",e),document.addEventListener("touchstart",n),document.addEventListener("click",i,!0)}function s(){document.removeEventListener("scroll",t),document.removeEventListener("keyup",e),document.removeEventListener("touchstart",n),document.removeEventListener("click",i,!0)}function a(t){null!==h&&(t?h.dispose():h.close(),s(),h=null)}function c(t){if(!document.body.classList.contains("zoom-overlay-open"))return t.metaKey||t.ctrlKey?void window.open(t.target.getAttribute("data-original")||t.target.src,"_blank"):void(t.target.width>=m()-v||(a(!0),h=new p(t.target,v),h.zoom(),r()))}var m=function(){return document.documentElement.clientWidth},u=function(){return document.documentElement.clientHeight},d=function(t){var e=t.getBoundingClientRect(),n=document.documentElement,o=window;return{top:e.top+o.pageYOffset-n.clientTop,left:e.left+o.pageXOffset-n.clientLeft}},l=function(t,e,n){var o=function(t){t.target.removeEventListener(e,o),n()};t.addEventListener(e,o)},f=function(t,e){this.w=t,this.h=e},p=function(t,e){this.img=t,this.preservedTransform=t.style.transform,this.wrap=null,this.overlay=null,this.offset=e};p.prototype.forceRepaint=function(){this.img.offsetWidth},p.prototype.zoom=function(){var t=new f(this.img.naturalWidth,this.img.naturalHeight);this.wrap=document.createElement("div"),this.wrap.classList.add("zoom-img-wrap"),this.img.parentNode.insertBefore(this.wrap,this.img),this.wrap.appendChild(this.img),this.img.classList.add("zoom-img"),this.img.setAttribute("data-action","zoom-out"),this.overlay=document.createElement("div"),this.overlay.classList.add("zoom-overlay"),document.body.appendChild(this.overlay),this.forceRepaint();var e=this.calculateScale(t);this.forceRepaint(),this.animate(e),document.body.classList.add("zoom-overlay-open")},p.prototype.calculateScale=function(t){var e=t.w/this.img.width,n=m()-this.offset,o=u()-this.offset,i=t.w/t.h,r=n/o;return t.w<n&&t.h<o?e:i<r?o/t.h*e:n/t.w*e},p.prototype.animate=function(t){var e=d(this.img),n=window.pageYOffset,o=m()/2,i=n+u()/2,r=e.left+this.img.width/2,s=e.top+this.img.height/2,a=o-r,c=i-s,l=0,f="scale("+t+")",p="translate3d("+a+"px, "+c+"px, "+l+"px)";this.img.style.transform=f,this.wrap.style.transform=p},p.prototype.dispose=function(){null!==this.wrap&&null!==this.wrap.parentNode&&(this.img.classList.remove("zoom-img"),this.img.setAttribute("data-action","zoom"),this.wrap.parentNode.insertBefore(this.img,this.wrap),this.wrap.parentNode.removeChild(this.wrap),document.body.removeChild(this.overlay),document.body.classList.remove("zoom-overlay-transitioning"))},p.prototype.close=function(){var t=this;document.body.classList.add("zoom-overlay-transitioning"),this.img.style.transform=this.preservedTransform,0===this.img.style.length&&this.img.removeAttribute("style"),this.wrap.style.transform="none",l(this.img,"transitionend",function(){t.dispose(),document.body.classList.remove("zoom-overlay-open")})};var h=null,v=80,g=-1,y=-1,w=function(t){return t.setAttribute("data-action","zoom"),t.addEventListener("click",c),function(){return t.removeEventListener("click",c)}};return w})}),i='img[data-action="zoom"] {\n cursor: pointer;\n cursor: -webkit-zoom-in;\n cursor: zoom-in;\n}\n.zoom-img,\n.zoom-img-wrap {\n position: relative;\n z-index: 666;\n transition: -webkit-transform 300ms cubic-bezier(.2,0,.2,1);\n transition: transform 300ms cubic-bezier(.2,0,.2,1);\n transition: transform 300ms cubic-bezier(.2,0,.2,1), -webkit-transform 300ms cubic-bezier(.2,0,.2,1);\n}\n.zoom-overlay {\n z-index: 420;\n background: #fff;\n position: fixed;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n pointer-events: none;\n opacity: 0;\n transition: opacity 300ms;\n}\n.zoom-overlay-open .zoom-overlay {\n opacity: 1;\n}\n.zoom-overlay-open {\n cursor: pointer;\n cursor: -webkit-zoom-out;\n cursor: zoom-out;\n}\n.zoom-overlay-transitioning {\n cursor: default;\n}\n.zoom-overlay-open.zoom-overlay-transitioning .zoom-overlay{\n opacity: 0;\n}\n';$docsify.plugins=[].concat(e,$docsify.plugins)}();
this.D=this.D||{},function(){"use strict";function t(t){var o,i=Docsify.dom;i.appendTo(i.head,i.create("style",n)),t.doneEach(function(t){var n=i.findAll("img:not(.emoji)");Array.isArray(o)&&o.length&&(o.forEach(function(t){return t()}),o=[]),o=n.map(e)})}var e=("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self,function(t,e){return e={exports:{}},t(e,e.exports),e.exports}(function(t,e){!function(e,n){t.exports=function(){function t(){-1===g&&(g=window.pageYOffset),Math.abs(g-window.pageYOffset)>=40&&a()}function e(t){27===t.keyCode&&a()}function n(t){var e=t.touches[0];null!==e&&(y=e.pageY,t.target.addEventListener("touchmove",o))}function o(t){var e=t.touches[0];null!==e&&Math.abs(e.pageY-y)>10&&(a(),t.target.removeEventListener("touchmove",o))}function i(){a()}function r(){document.addEventListener("scroll",t),document.addEventListener("keyup",e),document.addEventListener("touchstart",n),document.addEventListener("click",i,!0)}function s(){document.removeEventListener("scroll",t),document.removeEventListener("keyup",e),document.removeEventListener("touchstart",n),document.removeEventListener("click",i,!0)}function a(t){null!==h&&(t?h.dispose():h.close(),s(),h=null)}function c(t){if(!document.body.classList.contains("zoom-overlay-open"))return t.metaKey||t.ctrlKey?void window.open(t.target.getAttribute("data-original")||t.target.src,"_blank"):void(t.target.width>=m()-v||(a(!0),h=new p(t.target,v),h.zoom(),r()))}var m=function(){return document.documentElement.clientWidth},u=function(){return document.documentElement.clientHeight},d=function(t){var e=t.getBoundingClientRect(),n=document.documentElement,o=window;return{top:e.top+o.pageYOffset-n.clientTop,left:e.left+o.pageXOffset-n.clientLeft}},l=function(t,e,n){var o=function(t){t.target.removeEventListener(e,o),n()};t.addEventListener(e,o)},f=function(t,e){this.w=t,this.h=e},p=function(t,e){this.img=t,this.preservedTransform=t.style.transform,this.wrap=null,this.overlay=null,this.offset=e};p.prototype.forceRepaint=function(){this.img.offsetWidth},p.prototype.zoom=function(){var t=new f(this.img.naturalWidth,this.img.naturalHeight);this.wrap=document.createElement("div"),this.wrap.classList.add("zoom-img-wrap"),this.img.parentNode.insertBefore(this.wrap,this.img),this.wrap.appendChild(this.img),this.img.classList.add("zoom-img"),this.img.setAttribute("data-action","zoom-out"),this.overlay=document.createElement("div"),this.overlay.classList.add("zoom-overlay"),document.body.appendChild(this.overlay),this.forceRepaint();var e=this.calculateScale(t);this.forceRepaint(),this.animate(e),document.body.classList.add("zoom-overlay-open")},p.prototype.calculateScale=function(t){var e=t.w/this.img.width,n=m()-this.offset,o=u()-this.offset,i=t.w/t.h,r=n/o;return t.w<n&&t.h<o?e:i<r?o/t.h*e:n/t.w*e},p.prototype.animate=function(t){var e=d(this.img),n=window.pageYOffset,o=m()/2,i=n+u()/2,r=e.left+this.img.width/2,s=e.top+this.img.height/2,a=o-r,c=i-s,l="scale("+t+")",f="translate3d("+a+"px, "+c+"px, 0px)";this.img.style.transform=l,this.wrap.style.transform=f},p.prototype.dispose=function(){null!==this.wrap&&null!==this.wrap.parentNode&&(this.img.classList.remove("zoom-img"),this.img.setAttribute("data-action","zoom"),this.wrap.parentNode.insertBefore(this.img,this.wrap),this.wrap.parentNode.removeChild(this.wrap),document.body.removeChild(this.overlay),document.body.classList.remove("zoom-overlay-transitioning"))},p.prototype.close=function(){var t=this;document.body.classList.add("zoom-overlay-transitioning"),this.img.style.transform=this.preservedTransform,0===this.img.style.length&&this.img.removeAttribute("style"),this.wrap.style.transform="none",l(this.img,"transitionend",function(){t.dispose(),document.body.classList.remove("zoom-overlay-open")})};var h=null,v=80,g=-1,y=-1;return function(t){return t.setAttribute("data-action","zoom"),t.addEventListener("click",c),function(){return t.removeEventListener("click",c)}}}()}()})),n='img[data-action="zoom"] {\n cursor: pointer;\n cursor: -webkit-zoom-in;\n cursor: zoom-in;\n}\n.zoom-img,\n.zoom-img-wrap {\n position: relative;\n z-index: 666;\n transition: -webkit-transform 300ms cubic-bezier(.2,0,.2,1);\n transition: transform 300ms cubic-bezier(.2,0,.2,1);\n transition: transform 300ms cubic-bezier(.2,0,.2,1), -webkit-transform 300ms cubic-bezier(.2,0,.2,1);\n}\n.zoom-overlay {\n z-index: 420;\n background: #fff;\n position: fixed;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n pointer-events: none;\n opacity: 0;\n transition: opacity 300ms;\n}\n.zoom-overlay-open .zoom-overlay {\n opacity: 1;\n}\n.zoom-overlay-open {\n cursor: pointer;\n cursor: -webkit-zoom-out;\n cursor: zoom-out;\n}\n.zoom-overlay-transitioning {\n cursor: default;\n}\n.zoom-overlay-open.zoom-overlay-transitioning .zoom-overlay{\n opacity: 0;\n}\n';$docsify.plugins=[].concat(t,$docsify.plugins)}();
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+10 -5
View File
@@ -1,6 +1,6 @@
{
"name": "docsify",
"version": "3.5.0",
"version": "4.1.7",
"description": "A magical documentation generator.",
"author": {
"name": "qingwei-li",
@@ -20,14 +20,18 @@
"themes"
],
"scripts": {
"build": "rm -rf lib themes && node build/build.js && mkdir lib/themes && mkdir themes && node build/build-css.js",
"dev:build": "rm -rf lib themes && mkdir themes && node build/build.js --dev && node build/build-css.js --dev",
"dev": "node app.js & nodemon -w src -e js,css --exec 'npm run dev:build'",
"test": "eslint src"
"build": "rm -rf lib themes && node build/build && mkdir lib/themes && mkdir themes && node build/build-css && npm run build:ssr",
"dev:build": "rm -rf lib themes && mkdir themes && node build/build --dev && node build/build-css --dev",
"dev": "node app & nodemon -w src -e js,css --exec 'npm run dev:build'",
"build:ssr": "node build/build-ssr",
"test": "eslint {src,packages} --fix",
"pub:next": "RELEASE_TAG=next sh build/release.sh",
"pub": "sh build/release.sh"
},
"dependencies": {
"marked": "^0.3.6",
"prismjs": "^1.6.0",
"tinydate": "^1.0.0",
"zoom-image": "^0.1.4"
},
"devDependencies": {
@@ -39,6 +43,7 @@
"postcss": "^5.2.16",
"postcss-salad": "^1.0.8",
"rollup": "^0.41.6",
"rollup-plugin-async": "^1.2.0",
"rollup-plugin-buble": "^0.15.0",
"rollup-plugin-commonjs": "^8.0.2",
"rollup-plugin-node-resolve": "^2.0.0",
@@ -0,0 +1,4 @@
build.js
node_modules
*.log
.git
@@ -0,0 +1,46 @@
# docsify-server-renderer
## Install
```bash
yarn add docsify-server-render
```
## Usage
```js
var Renderer = require('docsify-server-renderer')
var readFileSync = require('fs').readFileSync
// init
var renderer = new Renderer({
template: readFileSync('./docs/index.template.html', 'utf-8').,
config: {
name: 'docsify',
repo: 'qingwei-li/docsify'
}
})
renderer.renderToString(url)
.then(html => {})
.catch(err => {})
```
*index.template.html*
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>docsify</title>
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<link rel="stylesheet" href="//unpkg.com/docsify/themes/buble.css" title="buble" disabled>
</head>
<body>
<!--inject-app-->
<!--inject-config-->
<script src="//unpkg.com/docsify/lib/docsify.js"></script>
</body>
</html>
```
+141
View File
@@ -0,0 +1,141 @@
import * as tpl from '../../src/core/render/tpl'
import fetch from 'node-fetch'
import { AbstractHistory } from '../../src/core/router/history/abstract'
import { Compiler } from '../../src/core/render/compiler'
import { isAbsolutePath } from '../../src/core/router/util'
import { readFileSync } from 'fs'
import { resolve, basename } from 'path'
import resolvePathname from 'resolve-pathname'
import debug from 'debug'
function cwd (...args) {
return resolve(process.cwd(), ...args)
}
function mainTpl (config) {
let html = `<nav class="app-nav${config.repo ? '' : ' no-badge'}"><!--navbar--></nav>`
if (config.repo) {
html += tpl.corner(config.repo)
}
if (config.coverpage) {
html += tpl.cover()
}
html += tpl.main(config)
return html
}
export default class Renderer {
constructor ({
template,
config,
cache
}) {
this.html = template
this.config = config = Object.assign({}, config, {
routerMode: 'history'
})
this.cache = cache
this.router = new AbstractHistory(config)
this.compiler = new Compiler(config, this.router)
this.router.getCurrentPath = () => this.url
this._renderHtml('inject-config', `<script>window.$docsify = ${JSON.stringify(config)}</script>`)
this._renderHtml('inject-app', mainTpl(config))
this.template = this.html
}
_getPath (url) {
const file = this.router.getFile(url)
return isAbsolutePath(file)
? file
: cwd(`./${file}`)
}
async renderToString (url) {
this.url = url = this.router.parse(url).path
const { loadSidebar, loadNavbar } = this.config
const mainFile = this._getPath(url)
this._renderHtml('main', await this._render(mainFile))
if (loadSidebar) {
const name = loadSidebar === true ? '_sidebar.md' : loadSidebar
const sidebarFile = this._getPath(resolve(url, `./${name}`))
this._renderHtml('sidebar', await this._render(sidebarFile, 'sidebar'))
}
if (loadNavbar) {
const name = loadNavbar === true ? '_navbar.md' : loadNavbar
const navbarFile = this._getPath(resolve(url, `./${name}`))
this._renderHtml('navbar', await this._render(navbarFile, 'navbar'))
}
const html = this.html
this.html = this.template
return html
}
_renderHtml (match, content) {
this.html = this.html.replace(new RegExp(`<!--${match}-->`, 'g'), content)
return this.html
}
async _render (path, type) {
let html = await this._loadFile(path)
const { subMaxLevel, maxLevel } = this.config
switch (type) {
case 'sidebar':
html = this.compiler.sidebar(html, maxLevel) +
`<script>window.__SUB_SIDEBAR__ = ${JSON.stringify(
this.compiler.subSidebar(subMaxLevel)
)}</script>`
break
case 'cover':
html = this.compiler.cover(html)
break
case 'navbar':
case 'article':
default:
html = this.compiler.compile(html)
break
}
return html
}
async _loadFile (filePath) {
debug('docsify')(`load > ${filePath}`)
let content
try {
if (isAbsolutePath(filePath)) {
const res = await fetch(filePath)
if (!res.ok) throw Error()
content = await res.text()
this.lock = 0
} else {
content = await readFileSync(filePath, 'utf8')
this.lock = 0
}
return content
} catch (e) {
this.lock = this.lock || 0
if (++this.lock > 10) {
this.lock = 0
return
}
const fileName = basename(filePath)
return await this._loadFile(resolvePathname(`../${fileName}`, filePath))
}
}
}
@@ -0,0 +1,22 @@
{
"name": "docsify-server-renderer",
"version": "4.1.7",
"description": "docsify server renderer",
"author": {
"name": "qingwei-li",
"email": "cinwell.li@gmail.com",
"url": "https://github.com/QingWei-Li"
},
"homepage": "https://docsify.js.org",
"license": "MIT",
"repository": "QingWei-Li/docsify",
"main": "build.js",
"scripts": {
"test": "echo 'hello'"
},
"dependencies": {
"debug": "^2.6.8",
"node-fetch": "^1.7.0",
"resolve-pathname": "^2.1.0"
}
}
+5 -1
View File
@@ -17,7 +17,11 @@ const config = merge({
autoHeader: false,
executeScript: null,
noEmoji: false,
ga: ''
ga: '',
mergeNavbar: false,
formatUpdated: '',
externalLinkTarget: '_blank',
routerModel: 'hash'
}, window.$docsify)
const script = document.currentScript ||
+2 -2
View File
@@ -6,13 +6,13 @@ import { scrollIntoView } from './scroll'
export function eventMixin (proto) {
proto.$resetEvents = function () {
scrollIntoView(this.route.query.id)
sidebar.getAndActive('nav')
sidebar.getAndActive(this.router, 'nav')
}
}
export function initEvent (vm) {
// Bind toggle button
sidebar.btn('button.sidebar-toggle')
sidebar.btn('button.sidebar-toggle', vm.router)
// Bind sticky effect
if (vm.config.coverpage) {
!isMobile && on('scroll', sidebar.sticky)
+2 -3
View File
@@ -1,6 +1,5 @@
import { isMobile } from '../util/env'
import * as dom from '../util/dom'
import { parse } from '../route/hash'
const nav = {}
let hoverOver = false
@@ -53,7 +52,7 @@ function highlight () {
}
}
export function scrollActiveSidebar () {
export function scrollActiveSidebar (router) {
if (isMobile) return
const sidebar = dom.getNode('.sidebar')
@@ -66,7 +65,7 @@ export function scrollActiveSidebar () {
let href = a.getAttribute('href')
if (href !== '/') {
href = parse(href).query.id
href = router.parse(href).query.id
}
nav[decodeURIComponent(href)] = li
+15 -10
View File
@@ -1,23 +1,27 @@
import { isMobile } from '../util/env'
import * as dom from '../util/dom'
import { getHash } from '../route/hash'
const title = dom.$.title
/**
* Toggle button
*/
export function btn (el) {
const toggle = () => dom.body.classList.toggle('close')
export function btn (el, router) {
const toggle = _ => dom.body.classList.toggle('close')
el = dom.getNode(el)
dom.on(el, 'click', toggle)
dom.on(el, 'click', e => {
e.stopPropagation()
toggle()
})
const sidebar = dom.getNode('.sidebar')
dom.on(sidebar, 'click', () => {
isMobile && toggle()
setTimeout(() => getAndActive(sidebar, true, true), 0)
})
isMobile && dom.on(dom.body, 'click', _ =>
dom.body.classList.contains('close') && toggle()
)
dom.on(sidebar, 'click', _ =>
setTimeout((_ => getAndActive(router, sidebar, true, true), 0))
)
}
export function sticky () {
@@ -34,16 +38,17 @@ export function sticky () {
/**
* Get and active link
* @param {object} router
* @param {string|element} el
* @param {Boolean} isParent acitve parent
* @param {Boolean} autoTitle auto set title
* @return {element}
*/
export function getAndActive (el, isParent, autoTitle) {
export function getAndActive (router, el, isParent, autoTitle) {
el = dom.getNode(el)
const links = dom.findAll(el, 'a')
const hash = '#' + getHash()
const hash = router.toURL(router.getCurrentPath())
let target
links
+11 -4
View File
@@ -14,9 +14,10 @@ export function get (url, hasBar = false) {
const on = function () {
xhr.addEventListener.apply(xhr, arguments)
}
const cached = cache[url]
if (cache[url]) {
return { then: cb => cb(cache[url]), abort: noop }
if (cached) {
return { then: cb => cb(cached.content, cached.opt), abort: noop }
}
xhr.open('GET', url)
@@ -41,8 +42,14 @@ export function get (url, hasBar = false) {
if (target.status >= 400) {
error(target)
} else {
cache[url] = target.response
success(target.response)
const result = cache[url] = {
content: target.response,
opt: {
updatedAt: xhr.getResponseHeader('last-modified')
}
}
success(result.content, result.opt)
}
})
},
+23 -7
View File
@@ -1,7 +1,8 @@
import { get } from './ajax'
import { callHook } from '../init/lifecycle'
import { getParentPath } from '../route/util'
import { getParentPath } from '../router/util'
import { noop } from '../util/core'
import { getAndActive } from '../event/sidebar'
function loadNested (path, file, next, vm, first) {
path = first ? path : path.replace(/\/$/, '')
@@ -9,7 +10,7 @@ function loadNested (path, file, next, vm, first) {
if (!path) return
get(vm.$getFile(path + file))
get(vm.router.getFile(path + file))
.then(next, _ => loadNested(path, file, next, vm))
}
@@ -22,14 +23,14 @@ export function fetchMixin (proto) {
// Abort last request
last && last.abort && last.abort()
last = get(this.$getFile(path), true)
last = get(this.router.getFile(path), true)
// Current page is html
this.isHTML = /\.html$/g.test(path)
// Load main content
last.then(text => {
this._renderMain(text)
last.then((text, opt) => {
this._renderMain(text, opt)
if (!loadSidebar) return cb()
const fn = result => { this._renderSidebar(result); cb() }
@@ -47,7 +48,7 @@ export function fetchMixin (proto) {
proto._fetchCover = function () {
const { coverpage } = this.config
const root = getParentPath(this.route.path)
const path = this.$getFile(root + coverpage)
const path = this.router.getFile(root + coverpage)
if (this.route.path !== '/' || !coverpage) {
this._renderCover()
@@ -70,5 +71,20 @@ export function fetchMixin (proto) {
}
export function initFetch (vm) {
vm.$fetch(_ => callHook(vm, 'ready'))
const { loadSidebar } = vm.config
// server-client renderer
if (vm.rendered) {
const activeEl = getAndActive(vm.router, '.sidebar-nav', true, true)
if (loadSidebar && activeEl) {
activeEl.parentNode.innerHTML += window.__SUB_SIDEBAR__
}
vm._bindEventOnRendered(activeEl)
vm._fetchCover()
vm.$resetEvents()
callHook(vm, 'doneEach')
callHook(vm, 'ready')
} else {
vm.$fetch(_ => callHook(vm, 'ready'))
}
}
+3 -3
View File
@@ -1,14 +1,14 @@
import * as util from './util'
import * as dom from './util/dom'
import * as render from './render/compiler'
import * as route from './route/hash'
import { Compiler } from './render/compiler'
import { slugify } from './render/slugify'
import { get } from './fetch/ajax'
import marked from 'marked'
import prism from 'prismjs'
export default function () {
window.Docsify = { util, dom, render, route, get, slugify }
window.Docsify = { util, dom, get, slugify }
window.DocsifyCompiler = Compiler
window.marked = marked
window.Prism = prism
}
+2 -2
View File
@@ -1,5 +1,5 @@
import { initMixin } from './init'
import { routeMixin } from './route'
import { routerMixin } from './router'
import { renderMixin } from './render'
import { fetchMixin } from './fetch'
import { eventMixin } from './event'
@@ -12,7 +12,7 @@ function Docsify () {
const proto = Docsify.prototype
initMixin(proto)
routeMixin(proto)
routerMixin(proto)
renderMixin(proto)
fetchMixin(proto)
eventMixin(proto)
+2 -2
View File
@@ -1,7 +1,7 @@
import config from '../config'
import { initLifecycle, callHook } from './lifecycle'
import { initRender } from '../render'
import { initRoute } from '../route'
import { initRouter } from '../router'
import { initEvent } from '../event'
import { initFetch } from '../fetch'
import { isFn } from '../util/core'
@@ -14,9 +14,9 @@ export function initMixin (proto) {
initLifecycle(vm) // Init hooks
initPlugin(vm) // Install plugins
callHook(vm, 'init')
initRouter(vm) // Add router
initRender(vm) // Render base DOM
initEvent(vm) // Bind events
initRoute(vm) // Add hashchange eventListener
initFetch(vm) // Fetch data
callHook(vm, 'mounted')
}
+134 -124
View File
@@ -4,155 +4,165 @@ import { helper as helperTpl, tree as treeTpl } from './tpl'
import { genTree } from './gen-tree'
import { slugify } from './slugify'
import { emojify } from './emojify'
import { toURL, parse } from '../route/hash'
import { getBasePath, isAbsolutePath, getPath } from '../route/util'
import { isAbsolutePath, getPath } from '../router/util'
import { isFn, merge, cached } from '../util/core'
let markdownCompiler = marked
let contentBase = ''
let currentPath = ''
let renderer = new marked.Renderer()
const cacheTree = {}
let toc = []
export class Compiler {
constructor (config, router) {
this.config = config
this.router = router
this.cacheTree = {}
this.toc = []
this.linkTarget = config.externalLinkTarget || '_blank'
this.contentBase = router.getBasePath()
/**
* Compile markdown content
*/
export const markdown = cached(text => {
let html = ''
const renderer = this._initRenderer()
let compile
const mdConf = config.markdown || {}
if (!text) return text
if (isFn(mdConf)) {
compile = mdConf(marked, renderer)
} else {
marked.setOptions(merge(mdConf, {
renderer: merge(renderer, mdConf.renderer)
}))
compile = marked
}
html = markdownCompiler(text)
html = emojify(html)
slugify.clear()
this.compile = cached(text => {
let html = ''
return html
})
if (!text) return text
markdown.renderer = renderer
html = compile(text)
html = config.noEmoji ? html : emojify(html)
slugify.clear()
markdown.init = function (config = {}, base = window.location.pathname) {
contentBase = getBasePath(base)
if (isFn(config)) {
markdownCompiler = config(marked, renderer)
} else {
renderer = merge(renderer, config.renderer)
marked.setOptions(merge(config, { renderer }))
}
}
markdown.update = function () {
currentPath = parse().path
}
/**
* render anchor tag
* @link https://github.com/chjj/marked#overriding-renderer-methods
*/
renderer.heading = function (text, level) {
const nextToc = { level, title: text }
if (/{docsify-ignore}/g.test(text)) {
text = text.replace('{docsify-ignore}', '')
nextToc.title = text
nextToc.ignoreSubHeading = true
return html
})
}
if (/{docsify-ignore-all}/g.test(text)) {
text = text.replace('{docsify-ignore-all}', '')
nextToc.title = text
nextToc.ignoreAllSubs = true
_initRenderer () {
const renderer = new marked.Renderer()
const { linkTarget, router, toc, contentBase } = this
/**
* render anchor tag
* @link https://github.com/chjj/marked#overriding-renderer-methods
*/
renderer.heading = function (text, level) {
const nextToc = { level, title: text }
if (/{docsify-ignore}/g.test(text)) {
text = text.replace('{docsify-ignore}', '')
nextToc.title = text
nextToc.ignoreSubHeading = true
}
if (/{docsify-ignore-all}/g.test(text)) {
text = text.replace('{docsify-ignore-all}', '')
nextToc.title = text
nextToc.ignoreAllSubs = true
}
const slug = slugify(text)
const url = router.toURL(router.getCurrentPath(), { id: slug })
nextToc.slug = url
toc.push(nextToc)
return `<h${level} id="${slug}"><a href="${url}" data-id="${slug}" class="anchor"><span>${text}</span></a></h${level}>`
}
// highlight code
renderer.code = function (code, lang = '') {
const hl = Prism.highlight(code, Prism.languages[lang] || Prism.languages.markup)
return `<pre v-pre data-lang="${lang}"><code class="lang-${lang}">${hl}</code></pre>`
}
renderer.link = function (href, title, text) {
let blank = ''
if (!/:|(\/{2})/.test(href)) {
href = router.toURL(href, null, router.getCurrentPath())
} else {
blank = ` target="${linkTarget}"`
}
if (title) {
title = ` title="${title}"`
}
return `<a href="${href}"${title || ''}${blank}>${text}</a>`
}
renderer.paragraph = function (text) {
if (/^!&gt;/.test(text)) {
return helperTpl('tip', text)
} else if (/^\?&gt;/.test(text)) {
return helperTpl('warn', text)
}
return `<p>${text}</p>`
}
renderer.image = function (href, title, text) {
let url = href
const titleHTML = title ? ` title="${title}"` : ''
if (!isAbsolutePath(href)) {
url = getPath(contentBase, href)
}
return `<img src="${url}" data-origin="${href}" alt="${text}"${titleHTML}>`
}
return renderer
}
const slug = slugify(text)
const url = toURL(currentPath, { id: slug })
nextToc.slug = url
toc.push(nextToc)
/**
* Compile sidebar
*/
sidebar (text, level) {
const currentPath = this.router.getCurrentPath()
let html = ''
return `<h${level} id="${slug}"><a href="${url}" data-id="${slug}" class="anchor"><span>${text}</span></a></h${level}>`
}
// highlight code
renderer.code = function (code, lang = '') {
const hl = Prism.highlight(code, Prism.languages[lang] || Prism.languages.markup)
if (text) {
html = this.compile(text)
html = html && html.match(/<ul[^>]*>([\s\S]+)<\/ul>/g)[0]
} else {
const tree = this.cacheTree[currentPath] || genTree(this.toc, level)
html = treeTpl(tree, '<ul>')
this.cacheTree[currentPath] = tree
}
return `<pre v-pre data-lang="${lang}"><code class="lang-${lang}">${hl}</code></pre>`
}
renderer.link = function (href, title, text) {
let blank = ''
if (!/:|(\/{2})/.test(href)) {
href = toURL(href)
} else {
blank = ' target="_blank"'
}
if (title) {
title = ` title="${title}"`
}
return `<a href="${href}"${title || ''}${blank}>${text}</a>`
}
renderer.paragraph = function (text) {
if (/^!&gt;/.test(text)) {
return helperTpl('tip', text)
} else if (/^\?&gt;/.test(text)) {
return helperTpl('warn', text)
}
return `<p>${text}</p>`
}
renderer.image = function (href, title, text) {
let url = href
const titleHTML = title ? ` title="${title}"` : ''
if (!isAbsolutePath(href)) {
url = getPath(contentBase, href)
return html
}
return `<img src="${url}" data-origin="${href}" alt="${text}"${titleHTML}>`
}
/**
* Compile sub sidebar
*/
subSidebar (level) {
const currentPath = this.router.getCurrentPath()
const { cacheTree, toc } = this
/**
* Compile sidebar
*/
export function sidebar (text, level) {
let html = ''
if (text) {
html = markdown(text)
html = html.match(/<ul[^>]*>([\s\S]+)<\/ul>/g)[0]
} else {
const tree = cacheTree[currentPath] || genTree(toc, level)
html = treeTpl(tree, '<ul>')
cacheTree[currentPath] = tree
}
return html
}
/**
* Compile sub sidebar
*/
export function subSidebar (el, level) {
if (el) {
toc[0] && toc[0].ignoreAllSubs && (toc = [])
toc[0] && toc[0].ignoreAllSubs && (this.toc = [])
toc[0] && toc[0].level === 1 && toc.shift()
toc.forEach((node, i) => {
node.ignoreSubHeading && toc.splice(i, 1)
})
const tree = cacheTree[currentPath] || genTree(toc, level)
el.parentNode.innerHTML += treeTpl(tree, '<ul class="app-sub-sidebar">')
cacheTree[currentPath] = tree
this.toc = []
return treeTpl(tree, '<ul class="app-sub-sidebar">')
}
toc = []
}
/**
* Compile cover page
*/
export function cover (text) {
const cacheToc = toc.slice()
const html = markdown(text)
article (text) {
return this.compile(text)
}
toc = cacheToc.slice()
/**
* Compile cover page
*/
cover (text) {
const cacheToc = this.toc.slice()
const html = this.compile(text)
return html
this.toc = cacheToc.slice()
return html
}
}
+4 -2
View File
@@ -1,10 +1,12 @@
import { inBrowser } from '../util/env'
function replace (m, $1) {
return '<img class="emoji" src="https://assets-cdn.github.com/images/icons/emoji/' + $1 + '.png" alt="' + $1 + '" />'
}
export function emojify (text) {
return $docsify.noEmoji ? text : text
return text
.replace(/<(pre|template|code)[^>]*?>[\s\S]+?<\/(pre|template|code)>/g, m => m.replace(/:/g, '__colon__'))
.replace(/:(\w+?):/ig, window.emojify || replace)
.replace(/:(\w+?):/ig, (inBrowser && window.emojify) || replace)
.replace(/__colon__/g, ':')
}
+70 -43
View File
@@ -1,12 +1,14 @@
import * as dom from '../util/dom'
import { getAndActive, sticky } from '../event/sidebar'
import { scrollActiveSidebar, scroll2Top } from '../event/scroll'
import cssVars from '../util/polyfill/css-vars'
import * as tpl from './tpl'
import { markdown, sidebar, subSidebar, cover } from './compiler'
import cssVars from '../util/polyfill/css-vars'
import tinydate from 'tinydate'
import { callHook } from '../init/lifecycle'
import { getBasePath, getPath, isAbsolutePath } from '../route/util'
import { Compiler } from './compiler'
import { getAndActive, sticky } from '../event/sidebar'
import { getPath, isAbsolutePath } from '../router/util'
import { isMobile } from '../util/env'
import { isPrimitive } from '../util/core'
import { scrollActiveSidebar, scroll2Top } from '../event/scroll'
function executeScript () {
const script = dom.findAll('.markdown-section>script')
@@ -20,6 +22,16 @@ function executeScript () {
}, 0)
}
function formatUpdated (html, updated, fn) {
updated = typeof fn === 'function'
? fn(updated)
: typeof fn === 'string'
? tinydate(fn)(new Date(updated))
: updated
return html.replace(/{docsify-updated}/g, updated)
}
function renderMain (html) {
if (!html) {
// TODO: Custom 404 page
@@ -42,10 +54,6 @@ function renderMain (html) {
} else {
this.config.executeScript && executeScript()
}
if (this.config.auto2top) {
scroll2Top(this.config.auto2top)
}
}
function renderNameLink (vm) {
@@ -58,7 +66,7 @@ function renderNameLink (vm) {
if (isPrimitive(vm.config.nameLink)) {
el.setAttribute('href', nameLink)
} else if (typeof nameLink === 'object') {
const match = Object.keys(nameLink).find(key => path.indexOf(key) > -1)
const match = Object.keys(nameLink).filter(key => path.indexOf(key) > -1)[0]
el.setAttribute('href', nameLink[match])
}
@@ -71,34 +79,47 @@ export function renderMixin (proto) {
}
proto._renderSidebar = function (text) {
const { maxLevel, subMaxLevel, autoHeader, loadSidebar } = this.config
const { maxLevel, subMaxLevel, loadSidebar } = this.config
this._renderTo('.sidebar-nav', sidebar(text, maxLevel))
const active = getAndActive('.sidebar-nav', true, true)
subSidebar(loadSidebar ? active : '', subMaxLevel)
this._renderTo('.sidebar-nav', this.compiler.sidebar(text, maxLevel))
const activeEl = getAndActive(this.router, '.sidebar-nav', true, true)
if (loadSidebar && activeEl) {
activeEl.parentNode.innerHTML += this.compiler.subSidebar(subMaxLevel)
}
// bind event
this.activeLink = active
scrollActiveSidebar()
this._bindEventOnRendered()
}
if (autoHeader && active) {
proto._bindEventOnRendered = function (activeEl) {
const { autoHeader, auto2top } = this.config
scrollActiveSidebar(this.router)
if (autoHeader && activeEl) {
const main = dom.getNode('#main')
const firstNode = main.children[0]
if (firstNode && firstNode.tagName !== 'H1') {
const h1 = dom.create('h1')
h1.innerText = active.innerText
h1.innerText = activeEl.innerText
dom.before(main, h1)
}
}
auto2top && scroll2Top(auto2top)
}
proto._renderNav = function (text) {
text && this._renderTo('nav', markdown(text))
getAndActive('nav')
text && this._renderTo('nav', this.compiler.compile(text))
getAndActive(this.router, 'nav')
}
proto._renderMain = function (text) {
proto._renderMain = function (text, opt = {}) {
callHook(this, 'beforeEach', text, result => {
const html = this.isHTML ? result : markdown(result)
let html = this.isHTML ? result : this.compiler.compile(result)
if (opt.updatedAt) {
html = formatUpdated(html, opt.updatedAt, this.config.formatUpdated)
}
callHook(this, 'afterEach', html, text => renderMain.call(this, text))
})
}
@@ -111,7 +132,7 @@ export function renderMixin (proto) {
}
dom.toggleClass(el, 'add', 'show')
let html = this.coverIsHTML ? text : cover(text)
let html = this.coverIsHTML ? text : this.compiler.cover(text)
const m = html.trim().match('<p><img.*?data-origin="(.*?)"[^a]+alt="(.*?)">([^<]*?)</p>$')
if (m) {
@@ -122,7 +143,7 @@ export function renderMixin (proto) {
dom.toggleClass(el, 'add', 'has-mask')
if (!isAbsolutePath(m[1])) {
path = getPath(getBasePath(this.config.basePath), m[1])
path = getPath(this.router.getBasePath(), m[1])
}
el.style.backgroundImage = `url(${path})`
el.style.backgroundSize = 'cover'
@@ -136,7 +157,6 @@ export function renderMixin (proto) {
}
proto._updateRender = function () {
markdown.update()
// render name link
renderNameLink(this)
}
@@ -146,35 +166,42 @@ export function initRender (vm) {
const config = vm.config
// Init markdown compiler
markdown.init(config.markdown, config.basePath)
vm.compiler = new Compiler(config, vm.router)
const id = config.el || '#app'
const navEl = dom.find('nav') || dom.create('nav')
let el = dom.find(id)
const el = dom.find(id)
let html = ''
let navAppendToTarget = dom.body
navEl.classList.add('app-nav')
if (el) {
if (config.repo) {
html += tpl.corner(config.repo)
}
if (config.coverpage) {
html += tpl.cover()
}
if (!config.repo) {
navEl.classList.add('no-badge')
html += tpl.main(config)
// Render main app
vm._renderTo(el, html, true)
} else {
vm.rendered = true
}
if (!el) {
el = dom.create(id)
dom.appendTo(dom.body, el)
}
if (config.repo) {
html += tpl.corner(config.repo)
}
if (config.coverpage) {
html += tpl.cover()
if (config.mergeNavbar && isMobile) {
navAppendToTarget = dom.find('.sidebar')
} else {
navEl.classList.add('app-nav')
if (!config.repo) {
navEl.classList.add('no-badge')
}
}
html += tpl.main(config)
// Render main app
vm._renderTo(el, html, true)
// Add nav
dom.before(dom.body, navEl)
dom.before(navAppendToTarget, navEl)
if (config.themeColor) {
dom.$.head.innerHTML += tpl.theme(config.themeColor)
+2 -2
View File
@@ -33,12 +33,12 @@ export function main (config) {
(config.name
? `<h1><a class="app-name-link" data-nosearch>${config.name}</a></h1>`
: '') +
'<div class="sidebar-nav"></div>' +
'<div class="sidebar-nav"><!--sidebar--></div>' +
'</aside>')
return (isMobile ? `${aside}<main>` : `<main>${aside}`) +
'<section class="content">' +
'<article class="markdown-section" id="main"></article>' +
'<article class="markdown-section" id="main"><!--main--></article>' +
'</section>' +
'</main>'
}
-76
View File
@@ -1,76 +0,0 @@
import { merge, cached } from '../util/core'
import { parseQuery, stringifyQuery, cleanPath } from './util'
export * from './util'
function replaceHash (path) {
const i = window.location.href.indexOf('#')
window.location.replace(
window.location.href.slice(0, i >= 0 ? i : 0) + '#' + path
)
}
const replaceSlug = cached(path => {
return path
.replace('#', '?id=')
.replace(/\?(\w+)=/g, (_, slug) => slug === 'id' ? '?id=' : `&${slug}=`)
})
/**
* Normalize the current url
*
* @example
* domain.com/docs/ => domain.com/docs/#/
* domain.com/docs/#/#slug => domain.com/docs/#/?id=slug
*/
export function normalize () {
let path = getHash()
path = replaceSlug(path)
if (path.charAt(0) === '/') return replaceHash(path)
replaceHash('/' + path)
}
export function getHash () {
// We can't use window.location.hash here because it's not
// consistent across browsers - Firefox will pre-decode it!
const href = window.location.href
const index = href.indexOf('#')
return index === -1 ? '' : href.slice(index + 1)
}
/**
* Parse the url
* @param {string} [path=window.location.herf]
* @return {object} { path, query }
*/
export function parse (path = window.location.href) {
let query = ''
const queryIndex = path.indexOf('?')
if (queryIndex >= 0) {
query = path.slice(queryIndex + 1)
path = path.slice(0, queryIndex)
}
const hashIndex = path.indexOf('#')
if (hashIndex) {
path = path.slice(hashIndex + 1)
}
return { path, query: parseQuery(query) }
}
/**
* to URL
* @param {string} path
* @param {object} qs query params
*/
export function toURL (path, params) {
const route = parse(replaceSlug(path))
route.query = merge({}, route.query, params)
path = route.path + stringifyQuery(route.query)
path = path.replace(/\.md/g, '')
return cleanPath('#/' + path)
}
-52
View File
@@ -1,52 +0,0 @@
import { normalize, parse } from './hash'
import { getBasePath, getPath, isAbsolutePath } from './util'
import { on } from '../util/dom'
function getAlias (path, alias) {
return alias[path] ? getAlias(alias[path], alias) : path
}
function getFileName (path) {
return /\.(md|html)$/g.test(path)
? path
: /\/$/g.test(path)
? `${path}README.md`
: `${path}.md`
}
export function routeMixin (proto) {
proto.route = {}
proto.$getFile = function (path) {
const { config } = this
const base = getBasePath(config.basePath)
path = config.alias ? getAlias(path, config.alias) : path
path = getFileName(path)
path = path === '/README.md' ? (config.homepage || path) : path
path = isAbsolutePath(path) ? path : getPath(base, path)
return path
}
}
let lastRoute = {}
export function initRoute (vm) {
normalize()
lastRoute = vm.route = parse()
vm._updateRender()
on('hashchange', _ => {
normalize()
vm.route = parse()
vm._updateRender()
if (lastRoute.path === vm.route.path) {
vm.$resetEvents()
return
}
vm.$fetch()
lastRoute = vm.route
})
}
+39
View File
@@ -0,0 +1,39 @@
import { History } from './base'
import { parseQuery, stringifyQuery, cleanPath } from '../util'
import { merge } from '../../util/core'
export class AbstractHistory extends History {
constructor (config) {
super(config)
this.mode = 'abstract'
}
parse (path) {
let query = ''
const queryIndex = path.indexOf('?')
if (queryIndex >= 0) {
query = path.slice(queryIndex + 1)
path = path.slice(0, queryIndex)
}
return {
path,
file: this.getFile(path),
query: parseQuery(query)
}
}
toURL (path, params, currentRoute) {
const local = currentRoute && path[0] === '#'
const route = this.parse(path)
route.query = merge({}, route.query, params)
path = route.path + stringifyQuery(route.query)
path = path.replace(/\.md(\?)|\.md$/, '$1')
if (local) path = currentRoute + path
return cleanPath('/' + path)
}
}
+50
View File
@@ -0,0 +1,50 @@
import { getPath, isAbsolutePath } from '../util'
import { noop } from '../../util/core'
function getAlias (path, alias) {
return alias[path] ? getAlias(alias[path], alias) : path
}
function getFileName (path) {
return /\.(md|html)$/g.test(path)
? path
: /\/$/g.test(path)
? `${path}README.md`
: `${path}.md`
}
export class History {
constructor (config) {
this.config = config
}
getBasePath () {
return this.config.basePath
}
getFile (path) {
path = path || this.getCurrentPath()
const { config } = this
const base = this.getBasePath()
path = config.alias ? getAlias(path, config.alias) : path
path = getFileName(path)
path = path === '/README.md' ? (config.homepage || path) : path
path = isAbsolutePath(path) ? path : getPath(base, path)
return path
}
onchange (cb = noop) {
cb()
}
getCurrentPath () {}
normalize () {}
parse () {}
toURL () {}
}
+91
View File
@@ -0,0 +1,91 @@
import { History } from './base'
import { merge, cached, noop } from '../../util/core'
import { on } from '../../util/dom'
import { parseQuery, stringifyQuery, cleanPath } from '../util'
function replaceHash (path) {
const i = location.href.indexOf('#')
location.replace(
location.href.slice(0, i >= 0 ? i : 0) + '#' + path
)
}
const replaceSlug = cached(path => {
return path.replace('#', '?id=')
})
export class HashHistory extends History {
constructor (config) {
super(config)
this.mode = 'hash'
}
getBasePath () {
const path = window.location.pathname || ''
const base = this.config.basePath
return /^(\/|https?:)/g.test(base)
? base
: cleanPath(path + '/' + base)
}
getCurrentPath () {
// We can't use location.hash here because it's not
// consistent across browsers - Firefox will pre-decode it!
const href = location.href
const index = href.indexOf('#')
return index === -1 ? '' : href.slice(index + 1)
}
onchange (cb = noop) {
on('hashchange', cb)
}
normalize () {
let path = this.getCurrentPath()
path = replaceSlug(path)
if (path.charAt(0) === '/') return replaceHash(path)
replaceHash('/' + path)
}
/**
* Parse the url
* @param {string} [path=location.herf]
* @return {object} { path, query }
*/
parse (path = location.href) {
let query = ''
const queryIndex = path.indexOf('?')
if (queryIndex >= 0) {
query = path.slice(queryIndex + 1)
path = path.slice(0, queryIndex)
}
const hashIndex = path.indexOf('#')
if (hashIndex) {
path = path.slice(hashIndex + 1)
}
return {
path,
file: this.getFile(path),
query: parseQuery(query)
}
}
toURL (path, params, currentRoute) {
const local = currentRoute && path[0] === '#'
const route = this.parse(replaceSlug(path))
route.query = merge({}, route.query, params)
path = route.path + stringifyQuery(route.query)
path = path.replace(/\.md(\?)|\.md$/, '$1')
if (local) path = currentRoute + path
return cleanPath('#/' + path)
}
}
+80
View File
@@ -0,0 +1,80 @@
import { History } from './base'
import { merge, noop } from '../../util/core'
import { on } from '../../util/dom'
import { parseQuery, stringifyQuery, getPath, cleanPath } from '../util'
export class HTML5History extends History {
constructor (config) {
super(config)
this.mode = 'history'
}
getCurrentPath () {
const base = this.getBasePath()
let path = window.location.pathname
if (base && path.indexOf(base) === 0) {
path = path.slice(base.length)
}
return (path || '/') + window.location.search + window.location.hash
}
onchange (cb = noop) {
on('click', e => {
const el = e.target.tagName === 'A'
? e.target
: e.target.parentNode
if (el.tagName === 'A' && !/_blank/.test(el.target)) {
e.preventDefault()
const url = el.href
window.history.pushState({ key: url }, '', url)
cb()
}
})
on('popstate', cb)
}
/**
* Parse the url
* @param {string} [path=location.href]
* @return {object} { path, query }
*/
parse (path = location.href) {
let query = ''
const queryIndex = path.indexOf('?')
if (queryIndex >= 0) {
query = path.slice(queryIndex + 1)
path = path.slice(0, queryIndex)
}
const base = getPath(location.origin)
const baseIndex = path.indexOf(base)
if (baseIndex > -1) {
path = path.slice(baseIndex + base.length)
}
return {
path,
file: this.getFile(path),
query: parseQuery(query)
}
}
toURL (path, params, currentRoute) {
const local = currentRoute && path[0] === '#'
const route = this.parse(path)
route.query = merge({}, route.query, params)
path = route.path + stringifyQuery(route.query)
path = path.replace(/\.md(\?)|\.md$/, '$1')
if (local) path = currentRoute + path
return cleanPath('/' + path)
}
}
+41
View File
@@ -0,0 +1,41 @@
import { HashHistory } from './history/hash'
import { HTML5History } from './history/html5'
import { supportsPushState } from '../util/env'
export function routerMixin (proto) {
proto.route = {}
}
let lastRoute = {}
export function initRouter (vm) {
const config = vm.config
const mode = config.routerMode || 'hash'
let router
if (mode === 'history' && supportsPushState) {
router = new HTML5History(config)
} else {
router = new HashHistory(config)
}
vm.router = router
router.normalize()
lastRoute = vm.route = router.parse()
vm._updateRender()
router.onchange(_ => {
router.normalize()
vm.route = router.parse()
vm._updateRender()
if (lastRoute.path === vm.route.path) {
vm.$resetEvents()
return
}
vm.$fetch()
lastRoute = vm.route
})
}
@@ -31,18 +31,12 @@ export function stringifyQuery (obj) {
return qs.length ? `?${qs.join('&')}` : ''
}
export const getBasePath = cached(base => {
return /^(\/|https?:)/g.test(base)
? base
: cleanPath(window.location.pathname + '/' + base)
})
export function getPath (...args) {
return cleanPath(args.join('/'))
}
export const isAbsolutePath = cached(path => {
return /(:|(\/{2}))/.test(path)
return /(:|(\/{2}))/g.test(path)
})
export const getParentPath = cached(path => {
@@ -54,5 +48,7 @@ export const getParentPath = cached(path => {
})
export const cleanPath = cached(path => {
return path.replace(/\/+/g, '/')
return path
.replace(/^\/+/, '/')
.replace(/([^:])\/{2,}/g, '$1/')
})
+13 -3
View File
@@ -1,5 +1,15 @@
export const UA = window.navigator.userAgent.toLowerCase()
export const inBrowser = typeof window !== 'undefined'
export const isIE = UA && /msie|trident/.test(UA)
export const isMobile = inBrowser && document.body.clientWidth <= 600
export const isMobile = document.body.clientWidth <= 600
/**
* @see https://github.com/MoOx/pjax/blob/master/lib/is-supported.js
*/
export const supportsPushState = inBrowser && (function () {
// Borrowed wholesale from https://github.com/defunkt/jquery-pjax
return window.history &&
window.history.pushState &&
window.history.replaceState &&
// pushState isnt reliable on iOS until 5.
!navigator.userAgent.match(/((iPod|iPhone|iPad).+\bOS\s+[1-4]\D|WebApps\/.+CFNetwork)/)
})()
+1
View File
@@ -1,2 +1,3 @@
export * from './core'
export * from './env'
export * from '../router/util'
+12 -8
View File
@@ -1,16 +1,20 @@
function handleExternalScript () {
const container = Docsify.dom.getNode('#main')
const script = Docsify.dom.find(container, 'script')
const scripts = Docsify.dom.findAll(container, 'script')
if (script && script.src) {
const newScript = document.createElement('script')
for (let i = scripts.length; i--;) {
const script = scripts[i]
;['src', 'async', 'defer'].forEach(attribute => {
newScript[attribute] = script[attribute]
})
if (script && script.src) {
const newScript = document.createElement('script')
script.parentNode.insertBefore(newScript, script)
script.parentNode.removeChild(script)
Array.prototype.slice.call(script.attributes).forEach(attribute => {
newScript[attribute.name] = attribute.value
})
script.parentNode.insertBefore(newScript, script)
script.parentNode.removeChild(script)
}
}
}
+14 -10
View File
@@ -7,24 +7,28 @@ function appendScript () {
}
function init (id) {
if (!window.ga) {
let ga = window.ga
if (!ga) {
appendScript()
window.ga = window.ga || function () {
(window.ga.q = window.ga.q || []).push(arguments)
ga = ga || function () {
(ga.q = ga.q || []).push(arguments)
}
window.ga.l = Number(new Date())
window.ga('create', id, 'auto')
ga.l = Number(new Date())
ga('create', id, 'auto')
}
return ga
}
function collect () {
init(window.$docsify.ga)
window.ga('set', 'page', location.href)
window.ga('send', 'pageview')
const ga = init($docsify.ga)
ga('set', 'page', location.hash)
ga('send', 'pageview')
}
const install = function (hook) {
if (!window.$docsify.ga) {
if (!$docsify.ga) {
console.error('[Docsify] ga is required.')
return
}
@@ -32,4 +36,4 @@ const install = function (hook) {
hook.beforeEach(collect)
}
window.$docsify.plugins = [].concat(install, window.$docsify.plugins)
$docsify.plugins = [].concat(install, $docsify.plugins)
+44 -39
View File
@@ -1,6 +1,5 @@
import { search } from './search'
let dom
let NO_DATA_TEXT = ''
function style () {
@@ -65,63 +64,67 @@ function style () {
.search p.empty {
text-align: center;
}`
const style = dom.create('style', code)
dom.appendTo(dom.head, style)
const style = Docsify.dom.create('style', code)
Docsify.dom.appendTo(Docsify.dom.head, style)
}
function tpl (opts) {
function tpl (opts, defaultValue = '') {
const html =
`<input type="search" />` +
`<input type="search" value="${defaultValue}" />` +
'<div class="results-panel"></div>' +
'</div>'
const el = dom.create('div', html)
const aside = dom.find('aside')
const el = Docsify.dom.create('div', html)
const aside = Docsify.dom.find('aside')
dom.toggleClass(el, 'search')
dom.before(aside, el)
Docsify.dom.toggleClass(el, 'search')
Docsify.dom.before(aside, el)
}
function doSearch (value) {
const $search = Docsify.dom.find('div.search')
const $panel = Docsify.dom.find($search, '.results-panel')
if (!value) {
$panel.classList.remove('show')
$panel.innerHTML = ''
return
}
const matchs = search(value)
let html = ''
matchs.forEach(post => {
html += `<div class="matching-post">
<h2><a href="${post.url}">${post.title}</a></h2>
<p>${post.content}</p>
</div>`
})
$panel.classList.add('show')
$panel.innerHTML = html || `<p class="empty">${NO_DATA_TEXT}</p>`
}
function bindEvents () {
const $search = dom.find('div.search')
const $input = dom.find($search, 'input')
const $panel = dom.find($search, '.results-panel')
const doSearch = function (value) {
if (!value) {
$panel.classList.remove('show')
$panel.innerHTML = ''
return
}
const matchs = search(value)
let html = ''
matchs.forEach(post => {
html += `<div class="matching-post">
<h2><a href="${post.url}">${post.title}</a></h2>
<p>${post.content}</p>
</div>`
})
$panel.classList.add('show')
$panel.innerHTML = html || `<p class="empty">${NO_DATA_TEXT}</p>`
}
const $search = Docsify.dom.find('div.search')
const $input = Docsify.dom.find($search, 'input')
let timeId
// Prevent to Fold sidebar
dom.on($search, 'click',
Docsify.dom.on($search, 'click',
e => e.target.tagName !== 'A' && e.stopPropagation())
dom.on($input, 'input', e => {
Docsify.dom.on($input, 'input', e => {
clearTimeout(timeId)
timeId = setTimeout(_ => doSearch(e.target.value.trim()), 100)
})
}
function updatePlaceholder (text, path) {
const $input = dom.getNode('.search input[type="search"]')
const $input = Docsify.dom.getNode('.search input[type="search"]')
if (!$input) return
if (typeof text === 'string') {
$input.placeholder = text
} else {
const match = Object.keys(text).find(key => path.indexOf(key) > -1)
const match = Object.keys(text).filter(key => path.indexOf(key) > -1)[0]
$input.placeholder = text[match]
}
}
@@ -130,16 +133,18 @@ function updateNoData (text, path) {
if (typeof text === 'string') {
NO_DATA_TEXT = text
} else {
const match = Object.keys(text).find(key => path.indexOf(key) > -1)
const match = Object.keys(text).filter(key => path.indexOf(key) > -1)[0]
NO_DATA_TEXT = text[match]
}
}
export function init (opts) {
dom = Docsify.dom
export function init (opts, vm) {
const keywords = vm.router.parse().query.s
style()
tpl(opts)
tpl(opts, keywords)
bindEvents()
keywords && setTimeout(_ => doSearch(keywords), 500)
}
export function update (opts, vm) {
+3 -3
View File
@@ -9,7 +9,7 @@ const CONFIG = {
}
const install = function (hook, vm) {
const util = Docsify.util
const { util } = Docsify
const opts = vm.config.search || CONFIG
if (Array.isArray(opts)) {
@@ -24,7 +24,7 @@ const install = function (hook, vm) {
const isAuto = CONFIG.paths === 'auto'
hook.mounted(_ => {
initComponet(CONFIG)
initComponet(CONFIG, vm)
!isAuto && initSearch(CONFIG, vm)
})
hook.doneEach(_ => {
@@ -33,4 +33,4 @@ const install = function (hook, vm) {
})
}
window.$docsify.plugins = [].concat(install, window.$docsify.plugins)
$docsify.plugins = [].concat(install, $docsify.plugins)
+8 -9
View File
@@ -14,18 +14,18 @@ function escapeHtml (string) {
return String(string).replace(/[&<>"'\/]/g, s => entityMap[s])
}
function getAllPaths () {
function getAllPaths (router) {
const paths = []
helper.dom.findAll('a:not([data-nosearch])')
.map(node => {
const href = node.href
const originHref = node.getAttribute('href')
const path = helper.route.parse(href).path
const path = router.parse(href).path
if (path &&
paths.indexOf(path) === -1 &&
!helper.route.isAbsolutePath(originHref)) {
!Docsify.util.isAbsolutePath(originHref)) {
paths.push(path)
}
})
@@ -38,16 +38,15 @@ function saveData (maxAge) {
localStorage.setItem('docsify.search.index', JSON.stringify(INDEXS))
}
export function genIndex (path, content = '') {
export function genIndex (path, content = '', router) {
const tokens = window.marked.lexer(content)
const slugify = window.Docsify.slugify
const toURL = Docsify.route.toURL
const index = {}
let slug
tokens.forEach(token => {
if (token.type === 'heading' && token.depth <= 2) {
slug = toURL(path, { id: slugify(token.text) })
slug = router.toURL(path, { id: slugify(token.text) })
index[slug] = { slug, title: token.text, body: '' }
} else {
if (!slug) return
@@ -145,7 +144,7 @@ export function init (config, vm) {
return
}
const paths = isAuto ? getAllPaths() : config.paths
const paths = isAuto ? getAllPaths(vm.router) : config.paths
const len = paths.length
let count = 0
@@ -153,9 +152,9 @@ export function init (config, vm) {
if (INDEXS[path]) return count++
helper
.get(vm.$getFile(path))
.get(vm.router.getFile(path))
.then(result => {
INDEXS[path] = genIndex(path, result)
INDEXS[path] = genIndex(path, result, vm.router)
len === ++count && saveData(config.maxAge)
})
})
+13 -8
View File
@@ -10,7 +10,7 @@
body:not(.ready) {
overflow: hidden;
[data-cloak], nav {
[data-cloak], .app-nav {
display: none;
}
}
@@ -83,7 +83,7 @@ kbd {
}
/* navbar */
nav.app-nav {
.app-nav {
left: 0;
margin: 25px 60px 0 0;
position: absolute;
@@ -238,6 +238,11 @@ main {
color: inherit;
text-decoration: none;
}
.app-nav {
display: block;
position: static;
}
}
ul {
@@ -325,7 +330,7 @@ body.sticky {
.markdown-section {
margin: 0 auto;
max-width: 800px;
padding: 20px 15px 40px 15px;
padding: 30px 15px 40px 15px;
position: relative;
> * {
@@ -430,7 +435,7 @@ body.close {
display: none;
}
nav {
.app-nav {
display: none;
}
}
@@ -440,11 +445,11 @@ body.close {
position: fixed;
}
nav {
.app-nav {
margin-top: 16px;
}
nav li ul {
.app-nav li ul {
top: 30px;
}
@@ -465,7 +470,7 @@ body.close {
transition: transform 250ms ease;
}
nav, .github-corner {
.app-nav, .github-corner {
transition: transform 250ms ease-out;
}
@@ -489,7 +494,7 @@ body.close {
transform: translateX($sidebar-width);
}
nav, .github-corner {
.app-nav, .github-corner {
display: none;
}
}
+550 -492
View File
File diff suppressed because it is too large Load Diff