mirror of
https://github.com/docsifyjs/docsify.git
synced 2025-12-08 19:55:52 +00:00
fix: ssr coverpage, fixed #273
This commit is contained in:
parent
ebc10c4e43
commit
9e824a4958
@ -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
|
||||
|
||||
|
||||
@ -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')
|
||||
|
||||
@ -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>'
|
||||
)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user