fix: ssr coverpage, fixed #273

This commit is contained in:
qingwei.li 2018-02-10 16:21:37 +08:00 committed by cinwell.li
parent ebc10c4e43
commit 9e824a4958
3 changed files with 23 additions and 6 deletions

View File

@ -13,9 +13,9 @@ function 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)
@ -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

View File

@ -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')

View File

@ -58,7 +58,7 @@ export function cover () {
return (
`<section class="cover show" style="background: ${bgc}">` +
'<div class="cover-main"></div>' +
'<div class="cover-main"><!--cover--></div>' +
'<div class="mask"></div>' +
'</section>'
)