fix: ssr coverpage, fixed #273
This commit is contained in:
parent
ebc10c4e43
commit
9e824a4958
3 changed files with 23 additions and 6 deletions
|
|
@ -13,9 +13,9 @@ function cwd (...args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function mainTpl (config) {
|
function mainTpl (config) {
|
||||||
let html = `<nav class="app-nav${config.repo
|
let html = `<nav class="app-nav${
|
||||||
? ''
|
config.repo ? '' : ' no-badge'
|
||||||
: ' no-badge'}"><!--navbar--></nav>`
|
}"><!--navbar--></nav>`
|
||||||
|
|
||||||
if (config.repo) {
|
if (config.repo) {
|
||||||
html += tpl.corner(config.repo)
|
html += tpl.corner(config.repo)
|
||||||
|
|
@ -58,7 +58,7 @@ export default class Renderer {
|
||||||
|
|
||||||
async renderToString (url) {
|
async renderToString (url) {
|
||||||
this.url = url = this.router.parse(url).path
|
this.url = url = this.router.parse(url).path
|
||||||
const { loadSidebar, loadNavbar } = this.config
|
const { loadSidebar, loadNavbar, coverpage } = this.config
|
||||||
|
|
||||||
const mainFile = this._getPath(url)
|
const mainFile = this._getPath(url)
|
||||||
this._renderHtml('main', await this._render(mainFile))
|
this._renderHtml('main', await this._render(mainFile))
|
||||||
|
|
@ -75,6 +75,24 @@ export default class Renderer {
|
||||||
this._renderHtml('navbar', await this._render(navbarFile, 'navbar'))
|
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
|
const html = this.html
|
||||||
this.html = this.template
|
this.html = this.template
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -127,7 +127,6 @@ export function initFetch (vm) {
|
||||||
activeEl.parentNode.innerHTML += window.__SUB_SIDEBAR__
|
activeEl.parentNode.innerHTML += window.__SUB_SIDEBAR__
|
||||||
}
|
}
|
||||||
vm._bindEventOnRendered(activeEl)
|
vm._bindEventOnRendered(activeEl)
|
||||||
vm._fetchCover()
|
|
||||||
vm.$resetEvents()
|
vm.$resetEvents()
|
||||||
callHook(vm, 'doneEach')
|
callHook(vm, 'doneEach')
|
||||||
callHook(vm, 'ready')
|
callHook(vm, 'ready')
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ export function cover () {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
`<section class="cover show" style="background: ${bgc}">` +
|
`<section class="cover show" style="background: ${bgc}">` +
|
||||||
'<div class="cover-main"></div>' +
|
'<div class="cover-main"><!--cover--></div>' +
|
||||||
'<div class="mask"></div>' +
|
'<div class="mask"></div>' +
|
||||||
'</section>'
|
'</section>'
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue