fix: Cache TOC for later usage in the case of cached file html (#649)

This commit is contained in:
程康 2018-10-23 08:24:22 +01:00 • committed by cinwell.li
commit 9e860177cb

View file

@ -85,7 +85,10 @@ export class Compiler {
} }
this._marked = compile this._marked = compile
this.compile = cached(text => { this.compile = text => {
let isCached = true
const result = cached(_ => {
isCached = false
let html = '' let html = ''
if (!text) { if (!text) {
@ -102,7 +105,18 @@ export class Compiler {
slugify.clear() slugify.clear()
return html return html
}) })(text)
const curFileName = this.router.parse().file
if (isCached) {
this.toc = this.cacheTOC[curFileName]
} else {
this.cacheTOC[curFileName] = [...this.toc]
}
return result
}
} }
compileEmbed(href, title) { compileEmbed(href, title) {