From 9e860177cb0703a37dff12d81693b668d5772a41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=B7?= Date: Tue, 23 Oct 2018 08:24:22 +0100 Subject: [PATCH] fix: Cache TOC for later usage in the case of cached file html (#649) --- src/core/render/compiler.js | 40 +++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/src/core/render/compiler.js b/src/core/render/compiler.js index 90e934c24..c27c4951e 100644 --- a/src/core/render/compiler.js +++ b/src/core/render/compiler.js @@ -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) {