diff --git a/packages/docsify-server-renderer/index.js b/packages/docsify-server-renderer/index.js index a885f9bfe..b0507efb4 100644 --- a/packages/docsify-server-renderer/index.js +++ b/packages/docsify-server-renderer/index.js @@ -13,9 +13,9 @@ function cwd (...args) { } function mainTpl (config) { - let html = `` + let html = `` if (config.repo) { html += tpl.corner(config.repo) @@ -58,7 +58,7 @@ export default class Renderer { async renderToString (url) { this.url = url = this.router.parse(url).path - const { loadSidebar, loadNavbar } = this.config + const { loadSidebar, loadNavbar, coverpage } = this.config const mainFile = this._getPath(url) this._renderHtml('main', await this._render(mainFile)) @@ -75,6 +75,24 @@ export default class Renderer { 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 diff --git a/src/core/fetch/index.js b/src/core/fetch/index.js index 4e898908d..16f396923 100644 --- a/src/core/fetch/index.js +++ b/src/core/fetch/index.js @@ -127,7 +127,6 @@ export function initFetch (vm) { activeEl.parentNode.innerHTML += window.__SUB_SIDEBAR__ } vm._bindEventOnRendered(activeEl) - vm._fetchCover() vm.$resetEvents() callHook(vm, 'doneEach') callHook(vm, 'ready') diff --git a/src/core/render/tpl.js b/src/core/render/tpl.js index 8db1caf0f..fb3ba941b 100644 --- a/src/core/render/tpl.js +++ b/src/core/render/tpl.js @@ -58,7 +58,7 @@ export function cover () { return ( `
` + - '
' + + '
' + '
' + '
' )