mirror of
https://github.com/docsifyjs/docsify.git
synced 2025-12-08 19:55:52 +00:00
feat(render): mutilple coverpage, close #315
This commit is contained in:
parent
9755439670
commit
f68ddf5af0
@ -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
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
@ -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>'
|
||||
@ -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>`
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user