Skip to content

Commit 9e824a4

Browse files
committed
fix: ssr coverpage, fixed #273
1 parent ebc10c4 commit 9e824a4

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

packages/docsify-server-renderer/index.js

+22-4
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ function cwd (...args) {
1313
}
1414

1515
function mainTpl (config) {
16-
let html = `<nav class="app-nav${config.repo
17-
? ''
18-
: ' no-badge'}"><!--navbar--></nav>`
16+
let html = `<nav class="app-nav${
17+
config.repo ? '' : ' no-badge'
18+
}"><!--navbar--></nav>`
1919

2020
if (config.repo) {
2121
html += tpl.corner(config.repo)
@@ -58,7 +58,7 @@ export default class Renderer {
5858

5959
async renderToString (url) {
6060
this.url = url = this.router.parse(url).path
61-
const { loadSidebar, loadNavbar } = this.config
61+
const { loadSidebar, loadNavbar, coverpage } = this.config
6262

6363
const mainFile = this._getPath(url)
6464
this._renderHtml('main', await this._render(mainFile))
@@ -75,6 +75,24 @@ export default class Renderer {
7575
this._renderHtml('navbar', await this._render(navbarFile, 'navbar'))
7676
}
7777

78+
if (coverpage) {
79+
let path = null
80+
if (typeof coverpage === 'string') {
81+
if (url === '/') {
82+
path = coverpage
83+
}
84+
} else if (Array.isArray(coverpage)) {
85+
path = coverpage.indexOf(url) > -1 && '_coverpage.md'
86+
} else {
87+
const cover = coverpage[url]
88+
path = cover === true ? '_coverpage.md' : cover
89+
}
90+
91+
const coverFile = this._getPath(resolve(url, `./${path}`))
92+
93+
this._renderHtml('cover', await this._render(coverFile), 'cover')
94+
}
95+
7896
const html = this.html
7997
this.html = this.template
8098

src/core/fetch/index.js

-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ export function initFetch (vm) {
127127
activeEl.parentNode.innerHTML += window.__SUB_SIDEBAR__
128128
}
129129
vm._bindEventOnRendered(activeEl)
130-
vm._fetchCover()
131130
vm.$resetEvents()
132131
callHook(vm, 'doneEach')
133132
callHook(vm, 'ready')

src/core/render/tpl.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export function cover () {
5858

5959
return (
6060
`<section class="cover show" style="background: ${bgc}">` +
61-
'<div class="cover-main"></div>' +
61+
'<div class="cover-main"><!--cover--></div>' +
6262
'<div class="mask"></div>' +
6363
'</section>'
6464
)

0 commit comments

Comments
 (0)