Skip to content

Commit

Permalink
feat(render): mutilple coverpage, close #315
Browse files Browse the repository at this point in the history
  • Loading branch information
QingWei-Li committed Feb 11, 2018
1 parent 9755439 commit f68ddf5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
32 changes: 23 additions & 9 deletions src/core/fetch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,31 @@ export function fetchMixin (proto) {
const { coverpage } = this.config
const query = this.route.query
const root = getParentPath(this.route.path)
const path = this.router.getFile(root + coverpage)

if (this.route.path !== '/' || !coverpage) {
this._renderCover()
return
}
if (coverpage) {
let path = null
const routePath = this.route.path
if (typeof coverpage === 'string') {
if (routePath === '/') {
path = coverpage
}
} else if (Array.isArray(coverpage)) {
path = coverpage.indexOf(routePath) > -1 && '_coverpage.md'
} else {
const cover = coverpage[routePath]
path = cover === true ? '_coverpage.md' : cover
}

this.coverIsHTML = /\.html$/g.test(path)
get(path + stringifyQuery(query, ['id'])).then(text =>
this._renderCover(text)
)
if (path) {
path = this.router.getFile(root + path)
this.coverIsHTML = /\.html$/g.test(path)
get(path + stringifyQuery(query, ['id'])).then(text =>
this._renderCover(text)
)
} else {
this._renderCover()
}
}
}

proto.$fetch = function (cb = noop) {
Expand Down
6 changes: 4 additions & 2 deletions src/core/render/tpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function cover () {
`hsl(${Math.floor(Math.random() * 255) + SL}) 100%)`

return (
`<section class="cover" style="background: ${bgc}">` +
`<section class="cover show" style="background: ${bgc}">` +
'<div class="cover-main"></div>' +
'<div class="mask"></div>' +
'</section>'
Expand All @@ -74,7 +74,9 @@ export function tree (toc, tpl = '') {
if (!toc || !toc.length) return ''

toc.forEach(node => {
tpl += `<li><a class="section-link" href="${node.slug}">${node.title}</a></li>`
tpl += `<li><a class="section-link" href="${node.slug}">${
node.title
}</a></li>`
if (node.children) {
tpl += `<li><ul class="children">${tree(node.children)}</li></ul>`
}
Expand Down

0 comments on commit f68ddf5

Please sign in to comment.