feat(render): mutilple coverpage, close #315
This commit is contained in:
parent
9755439670
commit
f68ddf5af0
2 changed files with 27 additions and 11 deletions
|
|
@ -70,17 +70,31 @@ export function fetchMixin (proto) {
|
||||||
const { coverpage } = this.config
|
const { coverpage } = this.config
|
||||||
const query = this.route.query
|
const query = this.route.query
|
||||||
const root = getParentPath(this.route.path)
|
const root = getParentPath(this.route.path)
|
||||||
const path = this.router.getFile(root + coverpage)
|
|
||||||
|
|
||||||
if (this.route.path !== '/' || !coverpage) {
|
if (coverpage) {
|
||||||
this._renderCover()
|
let path = null
|
||||||
return
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
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()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.coverIsHTML = /\.html$/g.test(path)
|
|
||||||
get(path + stringifyQuery(query, ['id'])).then(text =>
|
|
||||||
this._renderCover(text)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
proto.$fetch = function (cb = noop) {
|
proto.$fetch = function (cb = noop) {
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ export function cover () {
|
||||||
`hsl(${Math.floor(Math.random() * 255) + SL}) 100%)`
|
`hsl(${Math.floor(Math.random() * 255) + SL}) 100%)`
|
||||||
|
|
||||||
return (
|
return (
|
||||||
`<section class="cover" style="background: ${bgc}">` +
|
`<section class="cover show" style="background: ${bgc}">` +
|
||||||
'<div class="cover-main"></div>' +
|
'<div class="cover-main"></div>' +
|
||||||
'<div class="mask"></div>' +
|
'<div class="mask"></div>' +
|
||||||
'</section>'
|
'</section>'
|
||||||
|
|
@ -74,7 +74,9 @@ export function tree (toc, tpl = '') {
|
||||||
if (!toc || !toc.length) return ''
|
if (!toc || !toc.length) return ''
|
||||||
|
|
||||||
toc.forEach(node => {
|
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) {
|
if (node.children) {
|
||||||
tpl += `<li><ul class="children">${tree(node.children)}</li></ul>`
|
tpl += `<li><ul class="children">${tree(node.children)}</li></ul>`
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue