Skip to content

Commit 0abd234

Browse files
committed
优化导航获取方式
1 parent 175f57f commit 0abd234

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

lib/file-processor.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class FileProcessor {
2626
this.pages = pages;
2727
this.sourcePath = sourcePath;
2828
this.outputPath = outputPath;
29+
this.navigationCache = new Map();
2930

3031
this.templateEngine = new TemplateEngine(config.templatePath);
3132

@@ -51,6 +52,15 @@ class FileProcessor {
5152
false;
5253
}
5354

55+
// 获取缓存的导航数据
56+
getCachedNavigation(locale) {
57+
if (!this.navigationCache.has(locale)) {
58+
const navData = transformNavigation(this.config.nav, this.pages, this.config, locale);
59+
this.navigationCache.set(locale, navData);
60+
}
61+
return this.navigationCache.get(locale);
62+
}
63+
5464
// 解析元数据中的 EJS 模板
5565
parseMetadataTemplates(data, context) {
5666
const processed = {...data};
@@ -288,7 +298,7 @@ class FileProcessor {
288298
...this.config
289299
}
290300
}
291-
pageData.siteData.nav = transformNavigation(this.config.nav, this.pages, this.config, locale);
301+
pageData.siteData.nav = this.getCachedNavigation(locale);
292302

293303
// 渲染页面
294304
let html = await this.templateEngine.renderWithLayout('layouts/page', pageData);
@@ -334,7 +344,7 @@ class FileProcessor {
334344
...this.config
335345
}
336346
}
337-
pageData.siteData.nav = transformNavigation(this.config.nav, this.pages, this.config, locale);
347+
pageData.siteData.nav = this.getCachedNavigation(locale);
338348

339349
let html = await this.templateEngine.renderWithLayout('layouts/page', pageData);
340350

0 commit comments

Comments
 (0)