Skip to content

Commit 9e86017

Browse files
cheng-kangQingWei-Li
authored andcommitted
fix: Cache TOC for later usage in the case of cached file html (#649)
1 parent 47a8d5f commit 9e86017

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

src/core/render/compiler.js

+27-13
Original file line numberDiff line numberDiff line change
@@ -85,24 +85,38 @@ export class Compiler {
8585
}
8686

8787
this._marked = compile
88-
this.compile = cached(text => {
89-
let html = ''
88+
this.compile = text => {
89+
let isCached = true
90+
const result = cached(_ => {
91+
isCached = false
92+
let html = ''
93+
94+
if (!text) {
95+
return text
96+
}
9097

91-
if (!text) {
92-
return text
93-
}
98+
if (isPrimitive(text)) {
99+
html = compile(text)
100+
} else {
101+
html = compile.parser(text)
102+
}
103+
104+
html = config.noEmoji ? html : emojify(html)
105+
slugify.clear()
94106

95-
if (isPrimitive(text)) {
96-
html = compile(text)
107+
return html
108+
})(text)
109+
110+
const curFileName = this.router.parse().file
111+
112+
if (isCached) {
113+
this.toc = this.cacheTOC[curFileName]
97114
} else {
98-
html = compile.parser(text)
115+
this.cacheTOC[curFileName] = [...this.toc]
99116
}
100117

101-
html = config.noEmoji ? html : emojify(html)
102-
slugify.clear()
103-
104-
return html
105-
})
118+
return result
119+
}
106120
}
107121

108122
compileEmbed(href, title) {

0 commit comments

Comments
 (0)