fix: Cache TOC for later usage in the case of cached file html (#649)
This commit is contained in:
parent
47a8d5faa4
commit
9e860177cb
1 changed files with 27 additions and 13 deletions
|
|
@ -85,24 +85,38 @@ export class Compiler {
|
||||||
}
|
}
|
||||||
|
|
||||||
this._marked = compile
|
this._marked = compile
|
||||||
this.compile = cached(text => {
|
this.compile = text => {
|
||||||
let html = ''
|
let isCached = true
|
||||||
|
const result = cached(_ => {
|
||||||
|
isCached = false
|
||||||
|
let html = ''
|
||||||
|
|
||||||
if (!text) {
|
if (!text) {
|
||||||
return text
|
return text
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isPrimitive(text)) {
|
if (isPrimitive(text)) {
|
||||||
html = compile(text)
|
html = compile(text)
|
||||||
|
} else {
|
||||||
|
html = compile.parser(text)
|
||||||
|
}
|
||||||
|
|
||||||
|
html = config.noEmoji ? html : emojify(html)
|
||||||
|
slugify.clear()
|
||||||
|
|
||||||
|
return html
|
||||||
|
})(text)
|
||||||
|
|
||||||
|
const curFileName = this.router.parse().file
|
||||||
|
|
||||||
|
if (isCached) {
|
||||||
|
this.toc = this.cacheTOC[curFileName]
|
||||||
} else {
|
} else {
|
||||||
html = compile.parser(text)
|
this.cacheTOC[curFileName] = [...this.toc]
|
||||||
}
|
}
|
||||||
|
|
||||||
html = config.noEmoji ? html : emojify(html)
|
return result
|
||||||
slugify.clear()
|
}
|
||||||
|
|
||||||
return html
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
compileEmbed(href, title) {
|
compileEmbed(href, title) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue