fix(router): file ext

This commit is contained in:
cinwell.li 2019-03-31 11:55:25 +08:00
commit d9d9d114f4
3 changed files with 17 additions and 8 deletions

View file

@ -87,10 +87,13 @@ export default class Renderer {
this._renderHtml('navbar', await this._render(navbarFile, 'navbar')) this._renderHtml('navbar', await this._render(navbarFile, 'navbar'))
} }
if (coverpage === true) {
coverpage = '_coverpage.md'
}
if (coverpage) { if (coverpage) {
let path = null let path = null
if (typeof coverpage === 'string') { if (typeof coverpage === 'string') {
if (url === '/') { if (url === 'README.md') {
path = coverpage path = coverpage
} }
} else if (Array.isArray(coverpage)) { } else if (Array.isArray(coverpage)) {
@ -100,9 +103,11 @@ export default class Renderer {
path = cover === true ? '_coverpage.md' : cover path = cover === true ? '_coverpage.md' : cover
} }
const coverFile = this._getPath(resolve(url, `./${path}`)) if (path) {
const coverFile = this._getPath(resolve(url, `./${path}`))
this._renderHtml('cover', await this._render(coverFile), 'cover') this._renderHtml('cover', await this._render(coverFile), 'cover')
}
} }
const html = this.html const html = this.html
@ -174,7 +179,7 @@ export default class Renderer {
return content return content
} catch (e) { } catch (e) {
this.lock = this.lock || 0 this.lock = this.lock || 0
if (++this.lock > 10) { if (++this.lock > 4) {
this.lock = 0 this.lock = 0
return return
} }

View file

@ -22,8 +22,10 @@ function walkFetchEmbed({embedTokens, compile, fetch}, cb) {
} else if (token.embed.type === 'code') { } else if (token.embed.type === 'code') {
if (token.embed.fragment) { if (token.embed.fragment) {
const fragment = token.embed.fragment const fragment = token.embed.fragment
const pattern = new RegExp(`(?:###|\\/\\/\\/)\\s*\\[${fragment}\\]([\\s\\S]*)(?:###|\\/\\/\\/)\\s*\\[${fragment}\\]`) const pattern = new RegExp(
text = ((text.match(pattern) || [])[1] || '').trim() `(?:###|\\/\\/\\/)\\s*\\[${fragment}\\]([\\s\\S]*)(?:###|\\/\\/\\/)\\s*\\[${fragment}\\]`
)
text = ((text.match(pattern) || [])[1] || '').trim()
} }
embedToken = compile.lexer( embedToken = compile.lexer(
'```' + '```' +

View file

@ -21,9 +21,11 @@ function getAlias(path, alias, last) {
} }
function getFileName(path, ext) { function getFileName(path, ext) {
return new RegExp(`\\.(${ext.replace(/^\./, '')}|html)$`, 'g').test(path) ? return /\.\w+$/.test(path) ?
path : path :
/\/$/g.test(path) ? `${path}README${ext}` : `${path}${ext}` /\/$/g.test(path) ?
`${path}README${ext}` :
`${path}${ext}`
} }
export class History { export class History {