Skip to content

Commit

Permalink
fix: ssr coverpage, fixed #273
Browse files Browse the repository at this point in the history
  • Loading branch information
QingWei-Li committed Feb 11, 2018
1 parent 9ee9c65 commit 8b132d2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
26 changes: 22 additions & 4 deletions packages/docsify-server-renderer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand All @@ -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

Expand Down
1 change: 0 additions & 1 deletion src/core/fetch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion src/core/render/tpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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>'
)
Expand Down

0 comments on commit 8b132d2

Please sign in to comment.