From 42cfede04ed2aa2c05f839278f1f9e2bbc6cbc33 Mon Sep 17 00:00:00 2001 From: liqingwei Date: Thu, 21 Feb 2019 14:25:48 +0800 Subject: [PATCH] fix(ssr): relative path --- docs/docsify.config.js | 40 +++++++++++ docs/index.html | 81 +++++++---------------- docs/index.ssr.html | 64 ++++++++++++++++++ packages/docsify-server-renderer/index.js | 9 +-- 4 files changed, 132 insertions(+), 62 deletions(-) create mode 100644 docs/docsify.config.js create mode 100644 docs/index.ssr.html diff --git a/docs/docsify.config.js b/docs/docsify.config.js new file mode 100644 index 0000000..ec45cf1 --- /dev/null +++ b/docs/docsify.config.js @@ -0,0 +1,40 @@ +this.$docsify = { + alias: { + '.*?/awesome': 'https://raw.githubusercontent.com/docsifyjs/awesome-docsify/master/README.md', + '.*?/changelog': 'https://raw.githubusercontent.com/docsifyjs/docsify/master/CHANGELOG.md', + '/.*/_navbar.md': '/_navbar.md', + '/zh-cn/(.*)': 'https://raw.githubusercontent.com/docsifyjs/docs-zh/master/$1', + '/de-de/(.*)': 'https://raw.githubusercontent.com/docsifyjs/docs-de/master/$1', + '/ru/(.*)': 'https://raw.githubusercontent.com/docsifyjs/docs-ru/master/$1', + '/es/(.*)': 'https://raw.githubusercontent.com/docsifyjs/docs-es/master/$1' + }, + auto2top: true, + coverpage: true, + executeScript: true, + loadSidebar: true, + loadNavbar: true, + mergeNavbar: true, + maxLevel: 4, + subMaxLevel: 2, + ga: 'UA-106147152-1', + name: 'docsify', + search: { + noData: { + '/de-de/': 'Keine Ergebnisse!', + '/zh-cn/': '没有结果!', + '/': 'No results!' + }, + paths: 'auto', + placeholder: { + '/de-de/': 'Suche', + '/zh-cn/': '搜索', + '/': 'Search' + } + }, + formatUpdated: '{MM}/{DD} {HH}:{mm}' +} + +this.SSR_CONFIG = { + template: 'index.ssr.html', + config: this.$docsify +} \ No newline at end of file diff --git a/docs/index.html b/docs/index.html index e07c79e..16b6216 100644 --- a/docs/index.html +++ b/docs/index.html @@ -24,70 +24,35 @@
Loading ...
- + - + + + + + + + + + + + + + + + + + + + diff --git a/packages/docsify-server-renderer/index.js b/packages/docsify-server-renderer/index.js index c280fbd..ecf8324 100644 --- a/packages/docsify-server-renderer/index.js +++ b/packages/docsify-server-renderer/index.js @@ -31,12 +31,13 @@ function mainTpl(config) { } export default class Renderer { - constructor({template, config, cache}) { + constructor({template, config, cache, path}) { this.html = template this.config = config = Object.assign({}, config, { routerMode: 'history' }) this.cache = cache + this.path = path this.router = new AbstractHistory(config) this.compiler = new Compiler(config, this.router) @@ -54,7 +55,7 @@ export default class Renderer { _getPath(url) { const file = this.router.getFile(url) - return isAbsolutePath(file) ? file : cwd(`./${file}`) + return isAbsolutePath(file) ? file : cwd(this.path, `./${file}`) } async render(url) { @@ -76,13 +77,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(this.path, 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(this.path, url, `./${name}`)) this._renderHtml('navbar', await this._render(navbarFile, 'navbar')) }