Skip to content

Commit

Permalink
fix: Cache TOC for later usage in the case of cached file html (#649)
Browse files Browse the repository at this point in the history
  • Loading branch information
cheng-kang authored and QingWei-Li committed Oct 23, 2018
1 parent 47a8d5f commit 9e86017
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions src/core/render/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,38 @@ export class Compiler {
}

this._marked = compile
this.compile = cached(text => {
let html = ''
this.compile = text => {
let isCached = true
const result = cached(_ => {
isCached = false
let html = ''

if (!text) {
return text
}

if (!text) {
return text
}
if (isPrimitive(text)) {
html = compile(text)
} else {
html = compile.parser(text)
}

html = config.noEmoji ? html : emojify(html)
slugify.clear()

if (isPrimitive(text)) {
html = compile(text)
return html
})(text)

const curFileName = this.router.parse().file

if (isCached) {
this.toc = this.cacheTOC[curFileName]
} else {
html = compile.parser(text)
this.cacheTOC[curFileName] = [...this.toc]
}

html = config.noEmoji ? html : emojify(html)
slugify.clear()

return html
})
return result
}
}

compileEmbed(href, title) {
Expand Down

0 comments on commit 9e86017

Please sign in to comment.