mirror of
https://github.com/wahyd4/docsify.git
synced 2026-08-10 05:48:18 +10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f943fede99 | ||
|
|
e296439df3 | ||
|
|
0014895c19 | ||
|
|
23590fa7e7 | ||
|
|
8689a37121 | ||
|
|
05a0211861 | ||
|
|
318189a13f | ||
|
|
42795a0483 | ||
|
|
6b9e0922cf | ||
|
|
8cb4189b96 | ||
|
|
7eb6346075 | ||
|
|
238e9633f9 | ||
|
|
6db8c9e6c9 | ||
|
|
e160bcaded | ||
|
|
8cf69754b5 | ||
|
|
79a83bc17d | ||
|
|
81c87f7926 | ||
|
|
67ec128315 | ||
|
|
77657e3b64 | ||
|
|
9825db47af | ||
|
|
1a5593889e | ||
|
|
fc9cdf37c5 | ||
|
|
80dba191d3 | ||
|
|
5a0c37fcd3 | ||
|
|
1462efedcd | ||
|
|
4cb20a5f9d | ||
|
|
490c8a19d3 | ||
|
|
4b838247ea | ||
|
|
b091f3f10d | ||
|
|
0e74e6c15e | ||
|
|
be8358fcdc | ||
|
|
1ae0a9a845 | ||
|
|
7e169ad154 | ||
|
|
8595c99c0b | ||
|
|
43fc8b8ab1 | ||
|
|
ccec23df7f | ||
|
|
fc1cd3f11d | ||
|
|
3f38810774 | ||
|
|
3db4841da3 | ||
|
|
b764b6e32c | ||
|
|
46261572e3 |
@@ -1,5 +1,12 @@
|
||||
# Changelog
|
||||
|
||||
## 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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
+7
-1
@@ -1,4 +1,5 @@
|
||||
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'
|
||||
|
||||
@@ -6,7 +7,12 @@ rollup
|
||||
.rollup({
|
||||
entry: 'packages/docsify-server-renderer/index.js',
|
||||
plugins: [
|
||||
async()
|
||||
async(),
|
||||
buble({
|
||||
transforms: {
|
||||
generator: false
|
||||
}
|
||||
})
|
||||
],
|
||||
onwarn: function() {}
|
||||
})
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||

|
||||
|
||||
# docsify <small>3.7</small>
|
||||
# docsify <small>4.0</small>
|
||||
|
||||
> A magical documentation site generator.
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -317,7 +317,7 @@ window.$docsify = {
|
||||
```
|
||||
|
||||
## format-updated
|
||||
We can display the file update date through **{docsify-updated<span>}</span>** variable. And format it by `formatUpdated`.
|
||||
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 = {
|
||||
@@ -340,3 +340,10 @@ window.$docsify = {
|
||||
externalLinkTarget: '_self' // default: '_blank'
|
||||
}
|
||||
```
|
||||
|
||||
## router-mode
|
||||
```js
|
||||
window.$docsify = {
|
||||
routerMode: 'history' // default: 'hash'
|
||||
}
|
||||
```
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 => {})
|
||||
```
|
||||
@@ -1,33 +0,0 @@
|
||||
module.exports = {
|
||||
config: {
|
||||
alias: {
|
||||
'/de-de/changelog': '/changelog',
|
||||
'/zh-cn/changelog': '/changelog',
|
||||
'/changelog': 'https://raw.githubusercontent.com/QingWei-Li/docsify/master/CHANGELOG'
|
||||
},
|
||||
auto2top: true,
|
||||
coverpage: true,
|
||||
executeScript: true,
|
||||
loadSidebar: true,
|
||||
loadNavbar: true,
|
||||
mergeNavbar: true,
|
||||
maxLevel: 4,
|
||||
subMaxLevel: 2,
|
||||
name: 'docsify',
|
||||
search: {
|
||||
noData: {
|
||||
'/de-de/': 'Keine Ergebnisse!',
|
||||
'/zh-cn/': '没有结果!',
|
||||
'/': 'No results!'
|
||||
},
|
||||
paths: 'auto',
|
||||
placeholder: {
|
||||
'/de-de/': 'Suche',
|
||||
'/zh-cn/': '搜索',
|
||||
'/': 'Search'
|
||||
}
|
||||
}
|
||||
},
|
||||
context: './docs',
|
||||
template: './ssr.html'
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>docsify</title>
|
||||
<link rel="icon" href="_media/favicon.ico">
|
||||
<meta name="keywords" content="doc,docs,documentation,gitbook,creator,generator,github,jekyll,github-pages">
|
||||
<meta name="description" content="A magical documentation generator.">
|
||||
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
||||
<link rel="stylesheet" href="//unpkg.com/docsify@next/lib/themes/vue.css" title="vue">
|
||||
<link rel="stylesheet" href="//unpkg.com/docsify@next/lib/themes/dark.css" title="dark" disabled>
|
||||
<link rel="stylesheet" href="//unpkg.com/docsify@next/lib/themes/buble.css" title="buble" disabled>
|
||||
<link rel="stylesheet" href="//unpkg.com/docsify@next/lib/themes/pure.css" title="pure" disabled>
|
||||
<style>
|
||||
nav.app-nav li ul {
|
||||
min-width: 100px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<!--inject-app-->
|
||||
<!--inject-config-->
|
||||
</body>
|
||||
<script src="//unpkg.com/docsify@next/lib/docsify.min.js"></script>
|
||||
<script src="//unpkg.com/docsify@next/lib/plugins/search.min.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>
|
||||
+120
@@ -1,3 +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 => {})
|
||||
```
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 => {})
|
||||
```
|
||||
+36
-31
@@ -79,7 +79,8 @@ var config = merge({
|
||||
ga: '',
|
||||
mergeNavbar: false,
|
||||
formatUpdated: '',
|
||||
externalLinkTarget: '_blank'
|
||||
externalLinkTarget: '_blank',
|
||||
routerModel: 'hash'
|
||||
}, window.$docsify);
|
||||
|
||||
var script = document.currentScript ||
|
||||
@@ -2732,17 +2733,6 @@ function stringifyQuery (obj) {
|
||||
return qs.length ? ("?" + (qs.join('&'))) : ''
|
||||
}
|
||||
|
||||
var getBasePath = cached(function (base) {
|
||||
if ( base === void 0 ) base = '';
|
||||
|
||||
// TODO
|
||||
var path = inBrowser ? window.location.pathname : '';
|
||||
|
||||
return /^(\/|https?:)/g.test(base)
|
||||
? base
|
||||
: cleanPath(path + '/' + base)
|
||||
});
|
||||
|
||||
function getPath () {
|
||||
var args = [], len = arguments.length;
|
||||
while ( len-- ) args[ len ] = arguments[ len ];
|
||||
@@ -2751,7 +2741,7 @@ function getPath () {
|
||||
}
|
||||
|
||||
var isAbsolutePath = cached(function (path) {
|
||||
return /(:|(\/{2}))/.test(path)
|
||||
return /(:|(\/{2}))/g.test(path)
|
||||
});
|
||||
|
||||
var getParentPath = cached(function (path) {
|
||||
@@ -2774,7 +2764,7 @@ var Compiler = function Compiler (config, router) {
|
||||
this.cacheTree = {};
|
||||
this.toc = [];
|
||||
this.linkTarget = config.externalLinkTarget || '_blank';
|
||||
this.contentBase = getBasePath(config.basePath);
|
||||
this.contentBase = router.getBasePath();
|
||||
|
||||
var renderer = this._initRenderer();
|
||||
var compile;
|
||||
@@ -3233,7 +3223,7 @@ function renderMixin (proto) {
|
||||
|
||||
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';
|
||||
@@ -3317,10 +3307,16 @@ var History = function History (config) {
|
||||
this.config = config;
|
||||
};
|
||||
|
||||
History.prototype.getBasePath = function getBasePath () {
|
||||
return this.config.basePath
|
||||
};
|
||||
|
||||
History.prototype.getFile = function getFile (path) {
|
||||
path = path || this.getCurrentPath();
|
||||
|
||||
var ref = this;
|
||||
var config = ref.config;
|
||||
var base = getBasePath(config.basePath);
|
||||
var base = this.getBasePath();
|
||||
|
||||
path = config.alias ? getAlias(path, config.alias) : path;
|
||||
path = getFileName(path);
|
||||
@@ -3365,6 +3361,15 @@ var HashHistory = (function (History$$1) {
|
||||
HashHistory.prototype = Object.create( History$$1 && History$$1.prototype );
|
||||
HashHistory.prototype.constructor = HashHistory;
|
||||
|
||||
HashHistory.prototype.getBasePath = function getBasePath () {
|
||||
var path = window.location.pathname || '';
|
||||
var base = this.config.basePath;
|
||||
|
||||
return /^(\/|https?:)/g.test(base)
|
||||
? base
|
||||
: cleanPath(path + '/' + base)
|
||||
};
|
||||
|
||||
HashHistory.prototype.getCurrentPath = function getCurrentPath () {
|
||||
// We can't use location.hash here because it's not
|
||||
// consistent across browsers - Firefox will pre-decode it!
|
||||
@@ -3409,7 +3414,11 @@ var HashHistory = (function (History$$1) {
|
||||
path = path.slice(hashIndex + 1);
|
||||
}
|
||||
|
||||
return { path: path, query: parseQuery(query) }
|
||||
return {
|
||||
path: path,
|
||||
file: this.getFile(path),
|
||||
query: parseQuery(query)
|
||||
}
|
||||
};
|
||||
|
||||
HashHistory.prototype.toURL = function toURL (path, params, currentRoute) {
|
||||
@@ -3439,7 +3448,7 @@ var HTML5History = (function (History$$1) {
|
||||
HTML5History.prototype.constructor = HTML5History;
|
||||
|
||||
HTML5History.prototype.getCurrentPath = function getCurrentPath () {
|
||||
var base = this.config.basePath;
|
||||
var base = this.getBasePath();
|
||||
var path = window.location.pathname;
|
||||
|
||||
if (base && path.indexOf(base) === 0) {
|
||||
@@ -3468,15 +3477,6 @@ var HTML5History = (function (History$$1) {
|
||||
on('popstate', cb);
|
||||
};
|
||||
|
||||
HTML5History.prototype.normalize = function normalize () {
|
||||
var path = this.getCurrentPath();
|
||||
|
||||
path = path.replace('#', '?id=');
|
||||
window.history.pushState({ key: path }, '', path);
|
||||
|
||||
return path
|
||||
};
|
||||
|
||||
/**
|
||||
* Parse the url
|
||||
* @param {string} [path=location.href]
|
||||
@@ -3493,12 +3493,18 @@ var HTML5History = (function (History$$1) {
|
||||
path = path.slice(0, queryIndex);
|
||||
}
|
||||
|
||||
var baseIndex = path.indexOf(location.origin);
|
||||
var base = getPath(location.origin);
|
||||
var baseIndex = path.indexOf(base);
|
||||
|
||||
if (baseIndex > -1) {
|
||||
path = path.slice(baseIndex + location.origin.length);
|
||||
path = path.slice(baseIndex + base.length);
|
||||
}
|
||||
|
||||
return { path: path, query: parseQuery(query) }
|
||||
return {
|
||||
path: path,
|
||||
file: this.getFile(path),
|
||||
query: parseQuery(query)
|
||||
}
|
||||
};
|
||||
|
||||
HTML5History.prototype.toURL = function toURL (path, params, currentRoute) {
|
||||
@@ -3705,7 +3711,6 @@ var util = Object.freeze({
|
||||
supportsPushState: supportsPushState,
|
||||
parseQuery: parseQuery,
|
||||
stringifyQuery: stringifyQuery,
|
||||
getBasePath: getBasePath,
|
||||
getPath: getPath,
|
||||
isAbsolutePath: isAbsolutePath,
|
||||
getParentPath: getParentPath,
|
||||
|
||||
Vendored
+2
-2
File diff suppressed because one or more lines are too long
+15
-17
@@ -47,13 +47,12 @@ function genIndex (path, content, router) {
|
||||
|
||||
var tokens = window.marked.lexer(content);
|
||||
var slugify = window.Docsify.slugify;
|
||||
var toURL = router.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 }
|
||||
@@ -169,13 +168,12 @@ function init$1 (config, vm) {
|
||||
});
|
||||
}
|
||||
|
||||
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, defaultValue) {
|
||||
@@ -185,16 +183,16 @@ function tpl (opts, defaultValue) {
|
||||
"<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 = dom.find('div.search');
|
||||
var $panel = dom.find($search, '.results-panel');
|
||||
var $search = Docsify.dom.find('div.search');
|
||||
var $panel = Docsify.dom.find($search, '.results-panel');
|
||||
|
||||
if (!value) {
|
||||
$panel.classList.remove('show');
|
||||
@@ -213,22 +211,23 @@ function doSearch (value) {
|
||||
}
|
||||
|
||||
function bindEvents () {
|
||||
var $search = dom.find('div.search');
|
||||
var $input = dom.find($search, 'input');
|
||||
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 {
|
||||
@@ -247,7 +246,6 @@ function updateNoData (text, path) {
|
||||
}
|
||||
|
||||
function init$$1 (opts, vm) {
|
||||
dom = Docsify.dom;
|
||||
var keywords = vm.router.parse().query.s;
|
||||
|
||||
style();
|
||||
|
||||
Vendored
+1
-1
@@ -1 +1 @@
|
||||
this.D=this.D||{},function(){"use strict";function e(e){var n={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"};return String(e).replace(/[&<>"'\/]/g,function(e){return n[e]})}function n(e){var n=[];return d.dom.findAll("a:not([data-nosearch])").map(function(t){var r=t.href,a=t.getAttribute("href"),o=e.parse(r).path;o&&-1===n.indexOf(o)&&!Docsify.util.isAbsolutePath(a)&&n.push(o)}),n}function t(e){localStorage.setItem("docsify.search.expires",Date.now()+e),localStorage.setItem("docsify.search.index",JSON.stringify(v))}function r(e,n,t){void 0===n&&(n="");var r,a=window.marked.lexer(n),o=window.Docsify.slugify,i=t.toURL,s={};return a.forEach(function(n){if("heading"===n.type&&n.depth<=2)r=i(e,{id:o(n.text)}),s[r]={slug:r,title:n.text,body:""};else{if(!r)return;s[r]?s[r].body?s[r].body+="\n"+(n.text||""):s[r].body=n.text:s[r]={slug:r,title:"",body:""}}}),o.clear(),s}function a(n){var t=[],r=[];Object.keys(v).forEach(function(e){r=r.concat(Object.keys(v[e]).map(function(n){return v[e][n]}))}),n=[].concat(n,n.trim().split(/[\s\-\,\\\/]+/));for(var a=0;a<r.length;a++)!function(a){var o=r[a],i=!1,s="",c=o.title&&o.title.trim(),l=o.body&&o.body.trim(),u=o.slug||"";if(c&&l&&(n.forEach(function(n,t){var r=new RegExp(n,"gi"),a=-1,o=-1;if(a=c&&c.search(r),o=l&&l.search(r),a<0&&o<0)i=!1;else{i=!0,o<0&&(o=0);var u=0,p=0;u=o<11?0:o-10,p=0===u?70:o+n.length+60,p>l.length&&(p=l.length);var f="..."+e(l).substring(u,p).replace(r,'<em class="search-keyword">'+n+"</em>")+"...";s+=f}}),i)){var p={title:e(c),content:s,url:u};t.push(p)}}(a);return t}function o(e,a){d=Docsify;var o="auto"===e.paths,i=localStorage.getItem("docsify.search.expires")<Date.now();if(v=JSON.parse(localStorage.getItem("docsify.search.index")),i)v={};else if(!o)return;var s=o?n(a.router):e.paths,c=s.length,l=0;s.forEach(function(n){if(v[n])return l++;d.get(a.router.getFile(n)).then(function(o){v[n]=r(n,o,a.router),c===++l&&t(e.maxAge)})})}function i(){var e=g.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}");g.appendTo(g.head,e)}function s(e,n){void 0===n&&(n="");var t='<input type="search" value="'+n+'" /><div class="results-panel"></div></div>',r=g.create("div",t),a=g.find("aside");g.toggleClass(r,"search"),g.before(a,r)}function c(e){var n=g.find("div.search"),t=g.find(n,".results-panel");if(!e)return t.classList.remove("show"),void(t.innerHTML="");var r=a(e),o="";r.forEach(function(e){o+='<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=o||'<p class="empty">'+y+"</p>"}function l(){var e,n=g.find("div.search"),t=g.find(n,"input");g.on(n,"click",function(e){return"A"!==e.target.tagName&&e.stopPropagation()}),g.on(t,"input",function(n){clearTimeout(e),e=setTimeout(function(e){return c(n.target.value.trim())},100)})}function u(e,n){var t=g.getNode('.search input[type="search"]');if("string"==typeof e)t.placeholder=e;else{var r=Object.keys(e).filter(function(e){return n.indexOf(e)>-1})[0];t.placeholder=e[r]}}function p(e,n){if("string"==typeof e)y=e;else{var t=Object.keys(e).filter(function(e){return n.indexOf(e)>-1})[0];y=e[t]}}function f(e,n){g=Docsify.dom;var t=n.router.parse().query.s;i(),s(e,t),l(),t&&setTimeout(function(e){return c(t)},500)}function h(e,n){u(e.placeholder,n.route.path),p(e.noData,n.route.path)}var d,g,v={},y="",m={placeholder:"Type to search",noData:"No Results!",paths:"auto",maxAge:864e5},x=function(e,n){var t=Docsify.util,r=n.config.search||m;Array.isArray(r)?m.paths=r:"object"==typeof r&&(m.paths=Array.isArray(r.paths)?r.paths:"auto",m.maxAge=t.isPrimitive(r.maxAge)?r.maxAge:m.maxAge,m.placeholder=r.placeholder||m.placeholder,m.noData=r.noData||m.noData);var a="auto"===m.paths;e.mounted(function(e){f(m,n),!a&&o(m,n)}),e.doneEach(function(e){h(m,n),a&&o(m,n)})};$docsify.plugins=[].concat(x,$docsify.plugins)}();
|
||||
this.D=this.D||{},function(){"use strict";function e(e){var n={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"};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
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "docsify",
|
||||
"version": "4.0.0",
|
||||
"version": "4.1.7",
|
||||
"description": "A magical documentation generator.",
|
||||
"author": {
|
||||
"name": "qingwei-li",
|
||||
|
||||
@@ -15,14 +15,13 @@ var readFileSync = require('fs').readFileSync
|
||||
// init
|
||||
var renderer = new Renderer({
|
||||
template: readFileSync('./docs/index.template.html', 'utf-8').,
|
||||
context: './docs',
|
||||
config: {
|
||||
name: 'docsify',
|
||||
repo: 'qingwei-li/docsify'
|
||||
}
|
||||
})
|
||||
|
||||
renderer.renderToString({ url })
|
||||
renderer.renderToString(url)
|
||||
.then(html => {})
|
||||
.catch(err => {})
|
||||
```
|
||||
|
||||
@@ -5,13 +5,15 @@ 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>`
|
||||
let html = `<nav class="app-nav${config.repo ? '' : ' no-badge'}"><!--navbar--></nav>`
|
||||
|
||||
if (config.repo) {
|
||||
html += tpl.corner(config.repo)
|
||||
@@ -28,12 +30,10 @@ function mainTpl (config) {
|
||||
export default class Renderer {
|
||||
constructor ({
|
||||
template,
|
||||
context,
|
||||
config,
|
||||
cache
|
||||
}) {
|
||||
this.html = template
|
||||
this.context = cwd(context || './')
|
||||
this.config = config = Object.assign({}, config, {
|
||||
routerMode: 'history'
|
||||
})
|
||||
@@ -54,7 +54,7 @@ export default class Renderer {
|
||||
|
||||
return isAbsolutePath(file)
|
||||
? file
|
||||
: cwd(this.context, `./${file}`)
|
||||
: cwd(`./${file}`)
|
||||
}
|
||||
|
||||
async renderToString (url) {
|
||||
@@ -66,13 +66,13 @@ export default class Renderer {
|
||||
|
||||
if (loadSidebar) {
|
||||
const name = loadSidebar === true ? '_sidebar.md' : loadSidebar
|
||||
const sidebarFile = this._getPath(resolve(url, `../${name}`))
|
||||
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}`))
|
||||
const navbarFile = this._getPath(resolve(url, `./${name}`))
|
||||
this._renderHtml('navbar', await this._render(navbarFile, 'navbar'))
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ export default class Renderer {
|
||||
case 'sidebar':
|
||||
html = this.compiler.sidebar(html, maxLevel) +
|
||||
`<script>window.__SUB_SIDEBAR__ = ${JSON.stringify(
|
||||
this.compiler.subSidebar(html, subMaxLevel)
|
||||
this.compiler.subSidebar(subMaxLevel)
|
||||
)}</script>`
|
||||
break
|
||||
case 'cover':
|
||||
@@ -113,28 +113,29 @@ export default class Renderer {
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
if (isAbsolutePath(filePath)) {
|
||||
const res = await fetch(filePath)
|
||||
return await res.text()
|
||||
} else {
|
||||
return readFileSync(filePath, 'utf8')
|
||||
}
|
||||
} catch (e) {
|
||||
const fileName = basename(filePath)
|
||||
const parentPath = cwd(filePath, '../..')
|
||||
|
||||
if (this.context.length < parentPath.length) {
|
||||
throw Error(`Not found file ${fileName}`)
|
||||
}
|
||||
|
||||
await this._loadFile(cwd(filePath, '../..', fileName))
|
||||
return await this._loadFile(resolvePathname(`../${fileName}`, filePath))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "docsify-server-renderer",
|
||||
"version": "4.0.0",
|
||||
"version": "4.1.7",
|
||||
"description": "docsify server renderer",
|
||||
"author": {
|
||||
"name": "qingwei-li",
|
||||
@@ -15,6 +15,8 @@
|
||||
"test": "echo 'hello'"
|
||||
},
|
||||
"dependencies": {
|
||||
"node-fetch": "^1.7.0"
|
||||
"debug": "^2.6.8",
|
||||
"node-fetch": "^1.7.0",
|
||||
"resolve-pathname": "^2.1.0"
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -20,7 +20,8 @@ const config = merge({
|
||||
ga: '',
|
||||
mergeNavbar: false,
|
||||
formatUpdated: '',
|
||||
externalLinkTarget: '_blank'
|
||||
externalLinkTarget: '_blank',
|
||||
routerModel: 'hash'
|
||||
}, window.$docsify)
|
||||
|
||||
const script = document.currentScript ||
|
||||
|
||||
@@ -4,7 +4,7 @@ import { helper as helperTpl, tree as treeTpl } from './tpl'
|
||||
import { genTree } from './gen-tree'
|
||||
import { slugify } from './slugify'
|
||||
import { emojify } from './emojify'
|
||||
import { getBasePath, isAbsolutePath, getPath } from '../router/util'
|
||||
import { isAbsolutePath, getPath } from '../router/util'
|
||||
import { isFn, merge, cached } from '../util/core'
|
||||
|
||||
export class Compiler {
|
||||
@@ -14,7 +14,7 @@ export class Compiler {
|
||||
this.cacheTree = {}
|
||||
this.toc = []
|
||||
this.linkTarget = config.externalLinkTarget || '_blank'
|
||||
this.contentBase = getBasePath(config.basePath)
|
||||
this.contentBase = router.getBasePath()
|
||||
|
||||
const renderer = this._initRenderer()
|
||||
let compile
|
||||
|
||||
@@ -5,7 +5,7 @@ import tinydate from 'tinydate'
|
||||
import { callHook } from '../init/lifecycle'
|
||||
import { Compiler } from './compiler'
|
||||
import { getAndActive, sticky } from '../event/sidebar'
|
||||
import { getBasePath, getPath, isAbsolutePath } from '../router/util'
|
||||
import { getPath, isAbsolutePath } from '../router/util'
|
||||
import { isMobile } from '../util/env'
|
||||
import { isPrimitive } from '../util/core'
|
||||
import { scrollActiveSidebar, scroll2Top } from '../event/scroll'
|
||||
@@ -143,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'
|
||||
|
||||
@@ -17,7 +17,11 @@ export class AbstractHistory extends History {
|
||||
path = path.slice(0, queryIndex)
|
||||
}
|
||||
|
||||
return { path, query: parseQuery(query) }
|
||||
return {
|
||||
path,
|
||||
file: this.getFile(path),
|
||||
query: parseQuery(query)
|
||||
}
|
||||
}
|
||||
|
||||
toURL (path, params, currentRoute) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { getBasePath, getPath, isAbsolutePath } from '../util'
|
||||
import { getPath, isAbsolutePath } from '../util'
|
||||
import { noop } from '../../util/core'
|
||||
|
||||
function getAlias (path, alias) {
|
||||
@@ -18,9 +18,15 @@ export class History {
|
||||
this.config = config
|
||||
}
|
||||
|
||||
getBasePath () {
|
||||
return this.config.basePath
|
||||
}
|
||||
|
||||
getFile (path) {
|
||||
path = path || this.getCurrentPath()
|
||||
|
||||
const { config } = this
|
||||
const base = getBasePath(config.basePath)
|
||||
const base = this.getBasePath()
|
||||
|
||||
path = config.alias ? getAlias(path, config.alias) : path
|
||||
path = getFileName(path)
|
||||
|
||||
@@ -20,6 +20,15 @@ export class HashHistory extends History {
|
||||
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!
|
||||
@@ -60,7 +69,11 @@ export class HashHistory extends History {
|
||||
path = path.slice(hashIndex + 1)
|
||||
}
|
||||
|
||||
return { path, query: parseQuery(query) }
|
||||
return {
|
||||
path,
|
||||
file: this.getFile(path),
|
||||
query: parseQuery(query)
|
||||
}
|
||||
}
|
||||
|
||||
toURL (path, params, currentRoute) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { History } from './base'
|
||||
import { merge, noop } from '../../util/core'
|
||||
import { on } from '../../util/dom'
|
||||
import { parseQuery, stringifyQuery, cleanPath } from '../util'
|
||||
import { parseQuery, stringifyQuery, getPath, cleanPath } from '../util'
|
||||
|
||||
export class HTML5History extends History {
|
||||
constructor (config) {
|
||||
@@ -10,7 +10,7 @@ export class HTML5History extends History {
|
||||
}
|
||||
|
||||
getCurrentPath () {
|
||||
const base = this.config.basePath
|
||||
const base = this.getBasePath()
|
||||
let path = window.location.pathname
|
||||
|
||||
if (base && path.indexOf(base) === 0) {
|
||||
@@ -37,15 +37,6 @@ export class HTML5History extends History {
|
||||
on('popstate', cb)
|
||||
}
|
||||
|
||||
normalize () {
|
||||
let path = this.getCurrentPath()
|
||||
|
||||
path = path.replace('#', '?id=')
|
||||
window.history.pushState({ key: path }, '', path)
|
||||
|
||||
return path
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the url
|
||||
* @param {string} [path=location.href]
|
||||
@@ -60,12 +51,18 @@ export class HTML5History extends History {
|
||||
path = path.slice(0, queryIndex)
|
||||
}
|
||||
|
||||
const baseIndex = path.indexOf(location.origin)
|
||||
const base = getPath(location.origin)
|
||||
const baseIndex = path.indexOf(base)
|
||||
|
||||
if (baseIndex > -1) {
|
||||
path = path.slice(baseIndex + location.origin.length)
|
||||
path = path.slice(baseIndex + base.length)
|
||||
}
|
||||
|
||||
return { path, query: parseQuery(query) }
|
||||
return {
|
||||
path,
|
||||
file: this.getFile(path),
|
||||
query: parseQuery(query)
|
||||
}
|
||||
}
|
||||
|
||||
toURL (path, params, currentRoute) {
|
||||
|
||||
+1
-11
@@ -1,5 +1,4 @@
|
||||
import { cached } from '../util/core'
|
||||
import { inBrowser } from '../util/env'
|
||||
|
||||
const decode = decodeURIComponent
|
||||
const encode = encodeURIComponent
|
||||
@@ -32,21 +31,12 @@ export function stringifyQuery (obj) {
|
||||
return qs.length ? `?${qs.join('&')}` : ''
|
||||
}
|
||||
|
||||
export const getBasePath = cached((base = '') => {
|
||||
// TODO
|
||||
const path = inBrowser ? window.location.pathname : ''
|
||||
|
||||
return /^(\/|https?:)/g.test(base)
|
||||
? base
|
||||
: cleanPath(path + '/' + 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 => {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { search } from './search'
|
||||
|
||||
let dom
|
||||
let NO_DATA_TEXT = ''
|
||||
|
||||
function style () {
|
||||
@@ -65,8 +64,8 @@ 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, defaultValue = '') {
|
||||
@@ -74,16 +73,16 @@ function tpl (opts, defaultValue = '') {
|
||||
`<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 = dom.find('div.search')
|
||||
const $panel = dom.find($search, '.results-panel')
|
||||
const $search = Docsify.dom.find('div.search')
|
||||
const $panel = Docsify.dom.find($search, '.results-panel')
|
||||
|
||||
if (!value) {
|
||||
$panel.classList.remove('show')
|
||||
@@ -105,22 +104,23 @@ function doSearch (value) {
|
||||
}
|
||||
|
||||
function bindEvents () {
|
||||
const $search = dom.find('div.search')
|
||||
const $input = dom.find($search, 'input')
|
||||
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 {
|
||||
@@ -139,7 +139,6 @@ function updateNoData (text, path) {
|
||||
}
|
||||
|
||||
export function init (opts, vm) {
|
||||
dom = Docsify.dom
|
||||
const keywords = vm.router.parse().query.s
|
||||
|
||||
style()
|
||||
|
||||
@@ -41,13 +41,12 @@ function saveData (maxAge) {
|
||||
export function genIndex (path, content = '', router) {
|
||||
const tokens = window.marked.lexer(content)
|
||||
const slugify = window.Docsify.slugify
|
||||
const toURL = router.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
|
||||
|
||||
Reference in New Issue
Block a user