@@ -26,6 +26,7 @@ class FileProcessor {
26
26
this . pages = pages ;
27
27
this . sourcePath = sourcePath ;
28
28
this . outputPath = outputPath ;
29
+ this . navigationCache = new Map ( ) ;
29
30
30
31
this . templateEngine = new TemplateEngine ( config . templatePath ) ;
31
32
@@ -51,6 +52,15 @@ class FileProcessor {
51
52
false ;
52
53
}
53
54
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
+
54
64
// 解析元数据中的 EJS 模板
55
65
parseMetadataTemplates ( data , context ) {
56
66
const processed = { ...data } ;
@@ -288,7 +298,7 @@ class FileProcessor {
288
298
...this . config
289
299
}
290
300
}
291
- pageData . siteData . nav = transformNavigation ( this . config . nav , this . pages , this . config , locale ) ;
301
+ pageData . siteData . nav = this . getCachedNavigation ( locale ) ;
292
302
293
303
// 渲染页面
294
304
let html = await this . templateEngine . renderWithLayout ( 'layouts/page' , pageData ) ;
@@ -334,7 +344,7 @@ class FileProcessor {
334
344
...this . config
335
345
}
336
346
}
337
- pageData . siteData . nav = transformNavigation ( this . config . nav , this . pages , this . config , locale ) ;
347
+ pageData . siteData . nav = this . getCachedNavigation ( locale ) ;
338
348
339
349
let html = await this . templateEngine . renderWithLayout ( 'layouts/page' , pageData ) ;
340
350
0 commit comments