mirror of
https://gitee.com/docsifyjs/docsify.git
synced 2024-11-29 18:48:14 +08:00
refactor: delete the experimental and incomplete SSR feature
BREAKING: SSR removed Anyone depending on SSR will need to stay on an old Docsify version for now, move forward without SSR, or maintain SSR against a fork of updated Docsify. We have ideas on a better way to implement SSR, but these ideas have not been implemented yet.
This commit is contained in:
parent
4b9b464cbf
commit
8d5d20480a
@ -1,5 +1,5 @@
|
||||
{
|
||||
"sandboxes": ["2d17z"],
|
||||
"packages": [".", "packages/docsify-server-renderer"],
|
||||
"packages": ["."],
|
||||
"node": "16"
|
||||
}
|
||||
|
@ -4,6 +4,5 @@ build
|
||||
docs
|
||||
lib
|
||||
node_modules
|
||||
packages/docsify-server-renderer/build.js
|
||||
server.js
|
||||
themes
|
||||
|
@ -63,7 +63,6 @@ module.exports = {
|
||||
yoda: ['error', 'never'],
|
||||
|
||||
// Import rules
|
||||
// Search way how integrate with `lerna`
|
||||
'import/imports-first': ['error'],
|
||||
'import/newline-after-import': ['error'],
|
||||
'import/no-duplicates': ['error'],
|
||||
|
@ -5,6 +5,7 @@
|
||||
First, thank you for considering contributing to docsify! It's people like you that make the open source community such a great community! 😊
|
||||
|
||||
We welcome any type of contribution, not only code. You can help with
|
||||
|
||||
- **QA**: file bug reports, the more details you can give the better (e.g. screenshots with the console open)
|
||||
- **Marketing**: writing blog posts, howto's, printing stickers, ...
|
||||
- **Community**: presenting the project at meetups, organizing a dedicated meetup for the local community, ...
|
||||
@ -13,12 +14,50 @@ We welcome any type of contribution, not only code. You can help with
|
||||
|
||||
## Your First Contribution
|
||||
|
||||
Working on your first Pull Request? You can learn how from this *free* series, [How to Contribute to an Open Source Project on GitHub](https://app.egghead.io/playlists/how-to-contribute-to-an-open-source-project-on-github).
|
||||
Working on your first Pull Request ever? You can learn how from this _free_ series, [How to Contribute to an Open Source Project on GitHub](https://app.egghead.io/playlists/how-to-contribute-to-an-open-source-project-on-github).
|
||||
|
||||
## Online one-click setup for Contributing
|
||||
|
||||
You can use Gitpod (a free online VS Code-like IDE) for contributing. With a single click it'll launch a workspace and automatically:
|
||||
|
||||
- clone the docsify repo.
|
||||
- install the dependencies.
|
||||
- start `npm run dev`.
|
||||
|
||||
```bash
|
||||
npm install && npm run dev
|
||||
```
|
||||
|
||||
So that you can start straight away.
|
||||
|
||||
[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/docsifyjs/docsify)
|
||||
|
||||
- Fork it!
|
||||
- Create your feature branch: `git checkout -b my-new-feature`
|
||||
- Commit your changes: `git add . && git commit -m 'Add some feature'`
|
||||
- Push to the branch: `git push origin my-new-feature`
|
||||
- Submit a pull request
|
||||
|
||||
## Submitting code
|
||||
|
||||
Any code change should be submitted as a pull request. The description should explain what the code does and give steps to execute it. The pull request should also contain tests.
|
||||
|
||||
## Testing
|
||||
|
||||
Ensure that things work by running:
|
||||
|
||||
```sh
|
||||
npm test
|
||||
```
|
||||
|
||||
## Test Snapshots
|
||||
|
||||
If a snapshot fails, or to add new snapshots, run:
|
||||
|
||||
```sh
|
||||
npx jest --updateSnapshot
|
||||
```
|
||||
|
||||
## Code review process
|
||||
|
||||
The bigger the pull request, the longer it will take to review and merge. Try to break down large pull requests in smaller chunks that are easier to review and merge.
|
||||
@ -41,14 +80,12 @@ You can also reach us at hello@docsify.opencollective.com.
|
||||
Thank you to all the people who have already contributed to docsify!
|
||||
<a href="graphs/contributors"><img src="https://opencollective.com/docsify/contributors.svg?width=890" /></a>
|
||||
|
||||
|
||||
### Backers
|
||||
|
||||
Thank you to all our backers! [[Become a backer](https://opencollective.com/docsify#backer)]
|
||||
|
||||
<a href="https://opencollective.com/docsify#backers" target="_blank"><img src="https://opencollective.com/docsify/backers.svg?width=890"></a>
|
||||
|
||||
|
||||
### Sponsors
|
||||
|
||||
Thank you to all our sponsors! (please ask your company to also support this open source project by [becoming a sponsor](https://opencollective.com/docsify#sponsor))
|
||||
|
23
README.md
23
README.md
@ -44,7 +44,6 @@
|
||||
- Multiple themes
|
||||
- Useful plugin API
|
||||
- Compatible with IE11
|
||||
- Experimental SSR support ([example](https://github.com/docsifyjs/docsify-ssr-demo))
|
||||
- Support embedded files
|
||||
|
||||
## Quick start
|
||||
@ -68,27 +67,7 @@ Move to [awesome-docsify](https://github.com/docsifyjs/awesome-docsify#showcase)
|
||||
|
||||
## Contributing
|
||||
|
||||
### Online one-click setup for Contributing
|
||||
|
||||
You can use Gitpod (a free online VS Code-like IDE) for contributing. With a single click it'll launch a workspace and automatically:
|
||||
|
||||
- clone the docsify repo.
|
||||
- install the dependencies.
|
||||
- start `npm run dev`.
|
||||
|
||||
```bash
|
||||
npm install && npm run dev
|
||||
```
|
||||
|
||||
So that you can start straight away.
|
||||
|
||||
[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/docsifyjs/docsify)
|
||||
|
||||
- Fork it!
|
||||
- Create your feature branch: `git checkout -b my-new-feature`
|
||||
- Commit your changes: `git add . && git commit -m 'Add some feature'`
|
||||
- Push to the branch: `git push origin my-new-feature`
|
||||
- Submit a pull request
|
||||
See [CONTRIBUTING.md](./CONTRIBUTING.md).
|
||||
|
||||
## Backers
|
||||
|
||||
|
@ -30,7 +30,6 @@ async function build(opts) {
|
||||
nodeResolve(),
|
||||
replace({
|
||||
__VERSION__: version,
|
||||
'process.env.SSR': false
|
||||
})
|
||||
]),
|
||||
onwarn: function (message) {
|
||||
|
@ -12,22 +12,11 @@ echo
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
echo "Releasing $VERSION ..."
|
||||
|
||||
# Removing test script as non - availibity of tests. Will Add it once tests are completed
|
||||
|
||||
# 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 -
|
||||
# TODO
|
||||
# npm test
|
||||
|
||||
# commit
|
||||
git add -A
|
||||
|
35
build/ssr.js
35
build/ssr.js
@ -1,35 +0,0 @@
|
||||
var rollup = require('rollup')
|
||||
var buble = require('rollup-plugin-buble')
|
||||
var async = require('rollup-plugin-async')
|
||||
var replace = require('rollup-plugin-replace')
|
||||
|
||||
rollup
|
||||
.rollup({
|
||||
input: 'packages/docsify-server-renderer/index.js',
|
||||
plugins: [
|
||||
async(),
|
||||
replace({
|
||||
__VERSION__: process.env.VERSION || require('../package.json').version,
|
||||
'process.env.SSR': true
|
||||
}),
|
||||
buble({
|
||||
transforms: {
|
||||
generator: false
|
||||
}
|
||||
})
|
||||
],
|
||||
onwarn: function () {}
|
||||
})
|
||||
.then(function (bundle) {
|
||||
var dest = 'packages/docsify-server-renderer/build.js'
|
||||
|
||||
console.log(dest)
|
||||
return bundle.write({
|
||||
format: 'cjs',
|
||||
file: dest
|
||||
})
|
||||
})
|
||||
.catch(function (err) {
|
||||
console.error(err)
|
||||
process.exit(1)
|
||||
})
|
@ -17,7 +17,6 @@ See the [Quick start](quickstart.md) guide for more details.
|
||||
- Useful plugin API
|
||||
- Emoji support
|
||||
- Compatible with IE11
|
||||
- Support server-side rendering ([example](https://github.com/docsifyjs/docsify-ssr-demo))
|
||||
|
||||
## Examples
|
||||
|
||||
|
@ -22,7 +22,6 @@
|
||||
- [Vue compatibility](vue.md)
|
||||
- [CDN](cdn.md)
|
||||
- [Offline Mode (PWA)](pwa.md)
|
||||
- [Server-Side Rendering (SSR)](ssr.md)
|
||||
- [Embed Files](embed-files.md)
|
||||
|
||||
- [Awesome docsify](awesome.md)
|
||||
|
131
docs/ssr.md
131
docs/ssr.md
@ -1,131 +0,0 @@
|
||||
# Server-Side Rendering
|
||||
|
||||
!> :construction: SSR support is experimental and incomplete. We are working on it. Plugins and
|
||||
some features of Docsify will not work in SSR mode yet. :construction:
|
||||
|
||||
<!--
|
||||
This link is dead.
|
||||
See https://docsify.now.sh
|
||||
-->
|
||||
|
||||
Sample repo at https://github.com/docsifyjs/docsify-ssr-demo
|
||||
|
||||
## Why SSR?
|
||||
|
||||
- Better SEO
|
||||
- Feeling cool
|
||||
|
||||
## Quick start
|
||||
|
||||
Install `now` and `docsify-cli` in your project.
|
||||
|
||||
```bash
|
||||
npm i now docsify-cli -D
|
||||
```
|
||||
|
||||
Edit `package.json`. The below assumes the documentation is in the `./docs` subdirectory.
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "my-project",
|
||||
"scripts": {
|
||||
"start": "docsify start . -c ssr.config.js",
|
||||
"deploy": "now -p"
|
||||
},
|
||||
"files": [
|
||||
"docs"
|
||||
],
|
||||
"docsify": {
|
||||
"config": {
|
||||
"basePath": "https://docsify.js.org/",
|
||||
"loadSidebar": true,
|
||||
"loadNavbar": true,
|
||||
"coverpage": true,
|
||||
"name": "docsify"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
!> The `basePath` just like webpack `publicPath`. We can use local or remote files.
|
||||
|
||||
We can preview the local site to see if it works.
|
||||
|
||||
```bash
|
||||
npm start
|
||||
|
||||
# open http://localhost:4000
|
||||
```
|
||||
|
||||
Publish it!
|
||||
|
||||
```bash
|
||||
now -p
|
||||
```
|
||||
|
||||
Now, you have support for SSR.
|
||||
|
||||
## Custom template
|
||||
|
||||
You can provide a template for an 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, initial-scale=1.0, minimum-scale=1.0">
|
||||
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/docsify/themes/vue.css" title="vue">
|
||||
</head>
|
||||
<body>
|
||||
<!--inject-app-->
|
||||
<!--inject-config-->
|
||||
<script src="//cdn.jsdelivr.net/npm/docsify/lib/docsify.js"></script>
|
||||
<script src="//cdn.jsdelivr.net/npm/docsify/lib/plugins/search.js"></script>
|
||||
<script src="//cdn.jsdelivr.net/npm/prismjs/components/prism-bash.min.js"></script>
|
||||
<script src="//cdn.jsdelivr.net/npm/prismjs/components/prism-markdown.min.js"></script>
|
||||
<script src="//cdn.jsdelivr.net/npm/prismjs/components/prism-nginx.min.js"></script>
|
||||
</body>
|
||||
</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',
|
||||
maxAge: 60 * 60 * 1000, // lru-cache config
|
||||
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: 'docsifyjs/docsify'
|
||||
}
|
||||
})
|
||||
|
||||
renderer.renderToString(url)
|
||||
.then(html => {})
|
||||
.catch(err => {})
|
||||
```
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
|
||||
"version": "0.0.0"
|
||||
}
|
9826
package-lock.json
generated
9826
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -13,9 +13,6 @@
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/docsifyjs/docsify.git"
|
||||
},
|
||||
"workspaces": [
|
||||
"packages/*"
|
||||
],
|
||||
"main": "lib/docsify.js",
|
||||
"unpkg": "lib/docsify.min.js",
|
||||
"files": [
|
||||
@ -28,11 +25,9 @@
|
||||
"build:css": "mkdirp themes && npm run css -- -o themes",
|
||||
"build:emoji": "node ./build/emoji.js",
|
||||
"build:js": "cross-env NODE_ENV=production node build/build.js",
|
||||
"build:ssr": "node build/ssr.js",
|
||||
"build:test": "npm run build && npm test",
|
||||
"build": "rimraf lib themes && run-s build:js build:css build:css:min build:ssr build:cover build:emoji",
|
||||
"build": "rimraf lib themes && run-s build:js build:css build:css:min build:cover build:emoji",
|
||||
"css": "node build/css",
|
||||
"dev:ssr": "run-p serve:ssr watch:*",
|
||||
"dev": "run-p serve watch:*",
|
||||
"docker:build:test": "npm run docker:cli -- build:test",
|
||||
"docker:build": "docker build -f Dockerfile -t docsify-test:local .",
|
||||
@ -49,7 +44,6 @@
|
||||
"prepare": "npm run build",
|
||||
"pub:next": "cross-env RELEASE_TAG=next sh build/release.sh",
|
||||
"pub": "sh build/release.sh",
|
||||
"serve:ssr": "cross-env SSR=1 node server",
|
||||
"serve": "node server",
|
||||
"test:e2e": "playwright test",
|
||||
"test:integration": "jest --selectProjects integration",
|
||||
@ -98,7 +92,6 @@
|
||||
"eslint-plugin-prettier": "^4.0.0",
|
||||
"husky": "^8.0.3",
|
||||
"jest": "^27.4.7",
|
||||
"lerna": "^7.0.2",
|
||||
"lint-staged": "^13.2.2",
|
||||
"live-server": "^1.2.1",
|
||||
"mkdirp": "^3.0.0",
|
||||
|
5
packages/docsify-server-renderer/.gitignore
vendored
5
packages/docsify-server-renderer/.gitignore
vendored
@ -1,5 +0,0 @@
|
||||
build.js
|
||||
node_modules
|
||||
package-lock.json
|
||||
*.log
|
||||
.git
|
@ -1,46 +0,0 @@
|
||||
# docsify-server-renderer
|
||||
|
||||
## Install
|
||||
|
||||
```bash
|
||||
yarn add docsify-server-renderer
|
||||
```
|
||||
|
||||
## 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: 'docsifyjs/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, initial-scale=1.0, minimum-scale=1.0">
|
||||
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/docsify/themes/vue.css" title="vue">
|
||||
</head>
|
||||
<body>
|
||||
<!--inject-app-->
|
||||
<!--inject-config-->
|
||||
<script src="//cdn.jsdelivr.net/npm/docsify/lib/docsify.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
```
|
@ -1,212 +0,0 @@
|
||||
import { readFileSync } from 'fs';
|
||||
import { resolve, basename } from 'path';
|
||||
import resolvePathname from 'resolve-pathname';
|
||||
import fetch from 'node-fetch';
|
||||
import debug from 'debug';
|
||||
import { AbstractHistory } from '../../src/core/router/history/abstract';
|
||||
import { Compiler } from '../../src/core/render/compiler';
|
||||
import { isAbsolutePath } from '../../src/core/router/util';
|
||||
import * as tpl from '../../src/core/render/tpl';
|
||||
import { prerenderEmbed } from '../../src/core/render/embed';
|
||||
|
||||
function cwd(...args) {
|
||||
return resolve(process.cwd(), ...args);
|
||||
}
|
||||
|
||||
function isExternal(url) {
|
||||
let match = url.match(
|
||||
/^([^:/?#]+:)?(?:\/\/([^/?#]*))?([^?#]+)?(\?[^#]*)?(#.*)?/
|
||||
);
|
||||
if (
|
||||
typeof match[1] === 'string' &&
|
||||
match[1].length > 0 &&
|
||||
match[1].toLowerCase() !== location.protocol
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
if (
|
||||
typeof match[2] === 'string' &&
|
||||
match[2].length > 0 &&
|
||||
match[2].replace(
|
||||
new RegExp(
|
||||
':(' + { 'http:': 80, 'https:': 443 }[location.protocol] + ')?$'
|
||||
),
|
||||
''
|
||||
) !== location.host
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
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;
|
||||
this.isRemoteUrl = isExternal(this.url);
|
||||
const { loadSidebar, loadNavbar, coverpage } = this.config;
|
||||
|
||||
const mainFile = this._getPath(url);
|
||||
this._renderHtml('main', await this._render(mainFile, 'main'));
|
||||
|
||||
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'));
|
||||
}
|
||||
|
||||
if (coverpage) {
|
||||
let path = null;
|
||||
if (typeof coverpage === 'string') {
|
||||
if (url === '/') {
|
||||
path = coverpage;
|
||||
}
|
||||
} else if (Array.isArray(coverpage)) {
|
||||
path = coverpage.indexOf(url) > -1 && '_coverpage.md';
|
||||
} else {
|
||||
const cover = coverpage[url];
|
||||
path = cover === true ? '_coverpage.md' : cover;
|
||||
}
|
||||
|
||||
const coverFile = this._getPath(resolve(url, `./${path}`));
|
||||
|
||||
this._renderHtml('cover', await this._render(coverFile), 'cover');
|
||||
}
|
||||
|
||||
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;
|
||||
let tokens;
|
||||
|
||||
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 'main':
|
||||
tokens = await new Promise(r => {
|
||||
prerenderEmbed(
|
||||
{
|
||||
fetch: url => this._loadFile(this._getPath(url)),
|
||||
compiler: this.compiler,
|
||||
raw: html,
|
||||
},
|
||||
r
|
||||
);
|
||||
});
|
||||
html = this.compiler.compile(tokens);
|
||||
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);
|
||||
const result = await this._loadFile(
|
||||
resolvePathname(`../${fileName}`, filePath)
|
||||
);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Renderer.version = '__VERSION__';
|
@ -1,23 +0,0 @@
|
||||
{
|
||||
"name": "docsify-server-renderer",
|
||||
"version": "4.13.0",
|
||||
"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": "docsifyjs/docsify",
|
||||
"main": "build.js",
|
||||
"scripts": {
|
||||
"test": "echo 'hello'"
|
||||
},
|
||||
"dependencies": {
|
||||
"debug": "^4.3.4",
|
||||
"docsify": "^4.13.0",
|
||||
"node-fetch": "^3.3.1",
|
||||
"resolve-pathname": "^3.0.0"
|
||||
}
|
||||
}
|
45
server.js
45
server.js
@ -1,51 +1,6 @@
|
||||
const liveServer = require('live-server')
|
||||
const isSSR = !!process.env.SSR
|
||||
const middleware = []
|
||||
|
||||
if (isSSR) {
|
||||
const Renderer = require('./packages/docsify-server-renderer/build.js')
|
||||
const renderer = new Renderer({
|
||||
template: `
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>docsify</title>
|
||||
<meta name="viewport" content="width=device-width, initial-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: 'docsifyjs/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/docsifyjs/docsify/master/CHANGELOG'
|
||||
}
|
||||
},
|
||||
path: './'
|
||||
})
|
||||
|
||||
middleware.push(function(req, res, next) {
|
||||
if (/\.(css|js)$/.test(req.url)) {
|
||||
return next()
|
||||
}
|
||||
renderer.renderToString(req.url).then(html => res.end(html))
|
||||
})
|
||||
}
|
||||
|
||||
const params = {
|
||||
port: 3000,
|
||||
watch: ['lib', 'docs', 'themes'],
|
||||
|
@ -149,7 +149,7 @@ export class Compiler {
|
||||
if (config.include) {
|
||||
if (!isAbsolutePath(href)) {
|
||||
href = getPath(
|
||||
process.env.SSR ? '' : this.contentBase,
|
||||
this.contentBase,
|
||||
getParentPath(this.router.getCurrentPath()),
|
||||
href
|
||||
);
|
||||
|
@ -80,11 +80,7 @@ function walkFetchEmbed({ embedTokens, compile, fetch }, cb) {
|
||||
})(token);
|
||||
|
||||
if (token.embed.url) {
|
||||
if (process.env.SSR) {
|
||||
fetch(token.embed.url).then(next);
|
||||
} else {
|
||||
get(token.embed.url).then(next);
|
||||
}
|
||||
} else {
|
||||
next(token.embed.html);
|
||||
}
|
||||
|
@ -1,25 +0,0 @@
|
||||
import { parseQuery } from '../util';
|
||||
import { History } from './base';
|
||||
|
||||
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),
|
||||
};
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
export const inBrowser = !process.env.SSR;
|
||||
export const inBrowser = true; // True for now, may change when we add SSR.
|
||||
|
||||
export const isMobile = inBrowser && document.body.clientWidth <= 600;
|
||||
|
||||
|
@ -9,4 +9,4 @@ exports[`Docs Site coverpage renders and is unchanged 1`] = `
|
||||
|
||||
exports[`Docs Site navbar renders and is unchanged 1`] = `"<nav class=\\"app-nav no-badge\\"><ul><li>Translations<ul><li><a href=\\"#/\\" title=\\"undefined\\" class=\\"active\\"><img src=\\"https://github.githubassets.com/images/icons/emoji/unicode/1f1ec-1f1e7.png?v8.png\\" alt=\\"uk\\" class=\\"emoji\\" loading=\\"lazy\\"> English</a></li><li><a href=\\"#/zh-cn/\\" title=\\"undefined\\"><img src=\\"https://github.githubassets.com/images/icons/emoji/unicode/1f1e8-1f1f3.png?v8.png\\" alt=\\"cn\\" class=\\"emoji\\" loading=\\"lazy\\"> 简体中文</a></li><li><a href=\\"#/de-de/\\" title=\\"undefined\\"><img src=\\"https://github.githubassets.com/images/icons/emoji/unicode/1f1e9-1f1ea.png?v8.png\\" alt=\\"de\\" class=\\"emoji\\" loading=\\"lazy\\"> Deutsch</a></li><li><a href=\\"#/es/\\" title=\\"undefined\\"><img src=\\"https://github.githubassets.com/images/icons/emoji/unicode/1f1ea-1f1f8.png?v8.png\\" alt=\\"es\\" class=\\"emoji\\" loading=\\"lazy\\"> Español</a></li><li><a href=\\"#/ru-ru/\\" title=\\"undefined\\"><img src=\\"https://github.githubassets.com/images/icons/emoji/unicode/1f1f7-1f1fa.png?v8.png\\" alt=\\"ru\\" class=\\"emoji\\" loading=\\"lazy\\"> Русский</a></li></ul></li></ul></nav>"`;
|
||||
|
||||
exports[`Docs Site sidebar renders and is unchanged 1`] = `"<aside class=\\"sidebar\\"><div class=\\"sidebar-nav\\"><ul><li><p>Getting started</p><ul><li><a href=\\"#/quickstart\\" title=\\"undefined\\">Quick start</a></li><li><a href=\\"#/more-pages\\" title=\\"undefined\\">Writing more pages</a></li><li><a href=\\"#/custom-navbar\\" title=\\"undefined\\">Custom navbar</a></li><li><a href=\\"#/cover\\" title=\\"undefined\\">Cover page</a></li></ul></li><li><p>Customization</p><ul><li><a href=\\"#/configuration\\" title=\\"undefined\\">Configuration</a></li><li><a href=\\"#/themes\\" title=\\"undefined\\">Themes</a></li><li><a href=\\"#/plugins\\" title=\\"undefined\\">List of Plugins</a></li><li><a href=\\"#/write-a-plugin\\" title=\\"undefined\\">Write a Plugin</a></li><li><a href=\\"#/markdown\\" title=\\"undefined\\">Markdown configuration</a></li><li><a href=\\"#/language-highlight\\" title=\\"undefined\\">Language highlighting</a></li><li><a href=\\"#/emoji\\" title=\\"undefined\\">Emoji</a></li></ul></li><li><p>Guide</p><ul><li><a href=\\"#/deploy\\" title=\\"undefined\\">Deploy</a></li><li><a href=\\"#/helpers\\" title=\\"undefined\\">Helpers</a></li><li><a href=\\"#/vue\\" title=\\"undefined\\">Vue compatibility</a></li><li><a href=\\"#/cdn\\" title=\\"undefined\\">CDN</a></li><li><a href=\\"#/pwa\\" title=\\"undefined\\">Offline Mode (PWA)</a></li><li><a href=\\"#/ssr\\" title=\\"undefined\\">Server-Side Rendering (SSR)</a></li><li><a href=\\"#/embed-files\\" title=\\"undefined\\">Embed Files</a></li></ul></li><li><p><a href=\\"#/awesome\\" title=\\"undefined\\">Awesome docsify</a></p></li><li><p><a href=\\"#/changelog\\" title=\\"undefined\\">Changelog</a></p></li></ul></div></aside>"`;
|
||||
exports[`Docs Site sidebar renders and is unchanged 1`] = `"<aside class=\\"sidebar\\"><div class=\\"sidebar-nav\\"><ul><li><p>Getting started</p><ul><li><a href=\\"#/quickstart\\" title=\\"undefined\\">Quick start</a></li><li><a href=\\"#/more-pages\\" title=\\"undefined\\">Writing more pages</a></li><li><a href=\\"#/custom-navbar\\" title=\\"undefined\\">Custom navbar</a></li><li><a href=\\"#/cover\\" title=\\"undefined\\">Cover page</a></li></ul></li><li><p>Customization</p><ul><li><a href=\\"#/configuration\\" title=\\"undefined\\">Configuration</a></li><li><a href=\\"#/themes\\" title=\\"undefined\\">Themes</a></li><li><a href=\\"#/plugins\\" title=\\"undefined\\">List of Plugins</a></li><li><a href=\\"#/write-a-plugin\\" title=\\"undefined\\">Write a Plugin</a></li><li><a href=\\"#/markdown\\" title=\\"undefined\\">Markdown configuration</a></li><li><a href=\\"#/language-highlight\\" title=\\"undefined\\">Language highlighting</a></li><li><a href=\\"#/emoji\\" title=\\"undefined\\">Emoji</a></li></ul></li><li><p>Guide</p><ul><li><a href=\\"#/deploy\\" title=\\"undefined\\">Deploy</a></li><li><a href=\\"#/helpers\\" title=\\"undefined\\">Helpers</a></li><li><a href=\\"#/vue\\" title=\\"undefined\\">Vue compatibility</a></li><li><a href=\\"#/cdn\\" title=\\"undefined\\">CDN</a></li><li><a href=\\"#/pwa\\" title=\\"undefined\\">Offline Mode (PWA)</a></li><li><a href=\\"#/embed-files\\" title=\\"undefined\\">Embed Files</a></li></ul></li><li><p><a href=\\"#/awesome\\" title=\\"undefined\\">Awesome docsify</a></p></li><li><p><a href=\\"#/changelog\\" title=\\"undefined\\">Changelog</a></p></li></ul></div></aside>"`;
|
||||
|
Loading…
Reference in New Issue
Block a user