@@ -38,12 +38,14 @@ export class HTMLGenerator {
38
38
public static async beginBatch ( plugin : InvioPlugin , exportingFiles : TFile [ ] ) {
39
39
GlobalDataGenerator . clearGraphCache ( ) ;
40
40
GlobalDataGenerator . clearFileTreeCache ( ) ;
41
- const files = exportingFiles . map ( f => {
42
- const pageConfig = this . getPageOnlyMeta ( f ) ;
41
+ const filePromises = exportingFiles . map ( async f => {
42
+ const pageConfig = await this . getPageOnlyMeta ( f ) ;
43
43
( f as TFileWithMeta ) . sort = pageConfig ?. sort || 0
44
44
return f ;
45
45
} )
46
- GlobalDataGenerator . getFileTree ( files ) ;
46
+ Promise . all ( filePromises ) . then ( files => {
47
+ GlobalDataGenerator . getFileTree ( files ) ;
48
+ } )
47
49
await StatsView . activateStatsView ( plugin ) ;
48
50
const view = StatsView . getStatsView ( plugin , 'SyncingStats' ) ;
49
51
await AssetHandler . updateAssetCache ( view ) ;
@@ -56,13 +58,16 @@ export class HTMLGenerator {
56
58
}
57
59
58
60
// Only work before generaeWebpage
59
- public static updateTree ( patchFiles : TFile [ ] , delFiles : string [ ] ) {
60
- const files = patchFiles . map ( f => {
61
- const pageConfig = this . getPageOnlyMeta ( f ) ;
62
- ( f as TFileWithMeta ) . sort = pageConfig ?. sort || 0
63
- return f ;
64
- } )
65
- GlobalDataGenerator . updateFileTree ( files , delFiles )
61
+ public static async updateTree ( patchFiles : TFile [ ] , delFiles : string [ ] ) {
62
+ const promises = patchFiles . map ( f => {
63
+ return this . getPageOnlyMeta ( f ) . then ( pageConfig => {
64
+ ( f as TFileWithMeta ) . sort = pageConfig ?. sort || 0
65
+ return f ;
66
+ } )
67
+ } )
68
+ return Promise . all ( promises ) . then ( files => {
69
+ GlobalDataGenerator . updateFileTree ( files , delFiles )
70
+ } )
66
71
}
67
72
68
73
// rootPath is used for collecting context nodes
@@ -94,13 +99,13 @@ export class HTMLGenerator {
94
99
95
100
// inject outline
96
101
if ( InvioSettingTab . settings . includeOutline ) {
97
- let headerTree = LinkTree . headersFromFile ( file . markdownFile , 1 ) ;
102
+ let headerTree = await LinkTree . headersFromFile ( file . markdownFile , 1 ) ;
98
103
let outline : HTMLElement | undefined = this . generateHTMLTree ( headerTree , usingDocument , "Table Of Contents" , "outline-tree" , false , 1 , 2 , InvioSettingTab . settings . startOutlineCollapsed ) ;
99
104
rightSidebar . appendChild ( outline ) ;
100
105
}
101
106
102
107
// inject icon and title
103
- const config = this . getMeta ( file ) ;
108
+ const config = await this . getMeta ( file ) ;
104
109
const pageTitle = config ?. title || app . vault . getName ( ) ;
105
110
106
111
let brandHeader = this . generateBrandHeader ( usingDocument , config . brand , config . icon , config . slogan , config ?. home ) ;
@@ -389,8 +394,7 @@ export class HTMLGenerator {
389
394
}
390
395
391
396
private static async fillInHead ( file : ExportFile , rootPath : Path , remoteDomain : string = '' ) {
392
- // const pageConfig = app.metadataCache.getFileCache(file.markdownFile).frontmatter;
393
- const pageConfig = this . getMeta ( file ) ;
397
+ const pageConfig = await this . getMeta ( file ) ;
394
398
log . info ( 'get file metadata: ' , pageConfig , remoteDomain ) ;
395
399
log . info ( 'head with remote domain: ' , remoteDomain ) ;
396
400
let pageTitle = file . markdownFile . basename ;
@@ -583,26 +587,38 @@ export class HTMLGenerator {
583
587
}
584
588
} )
585
589
}
586
-
587
-
588
590
}
589
591
590
- private static getPageOnlyMeta ( file : TFile ) {
591
- const pageConfig = ( app . metadataCache . getFileCache ( file ) . frontmatter || { } ) as IMetaConfig ;
592
+ private static async getPageOnlyMeta ( file : TFile ) {
593
+ let cache = app . metadataCache . getFileCache ( file ) ;
594
+ if ( ! cache ) {
595
+ await app . vault . adapter . read ( file . path ) ;
596
+ cache = app . metadataCache . getFileCache ( file ) ;
597
+ }
598
+ const pageConfig = ( cache ?. frontmatter || { } ) as IMetaConfig ;
592
599
return pageConfig ;
593
600
}
594
- private static getMeta ( file : ExportFile ) : IMetaConfig {
601
+ private static async getMeta ( file : ExportFile ) : Promise < IMetaConfig > {
595
602
// Get site config
596
603
const indexPath = file . exportedFolder . joinString ( 'index.md' ) ;
597
604
const indexFile = app . vault . getAbstractFileByPath ( indexPath . asString ) ;
598
605
599
- const pageConfig = ( app . metadataCache . getFileCache ( file . markdownFile ) . frontmatter || { } ) as IMetaConfig ;
606
+ let meta = app . metadataCache . getFileCache ( file . markdownFile ) ;
607
+ if ( ! meta ) {
608
+ await app . vault . adapter . read ( file . markdownFile . path )
609
+ meta = app . metadataCache . getFileCache ( file . markdownFile ) ;
610
+ }
611
+ const pageConfig = ( meta ?. frontmatter || { } ) as IMetaConfig ;
600
612
log . info ( 'page config: ' , pageConfig ) ;
601
613
602
614
const siteConfig : IMetaConfig = { } ;
603
615
if ( indexFile instanceof TFile ) {
604
- const indexMeta = app . metadataCache . getFileCache ( indexFile ) ;
605
- Object . assign ( siteConfig , indexMeta ?. frontmatter || { } ) ;
616
+ let meta = app . metadataCache . getFileCache ( indexFile ) ;
617
+ if ( ! meta ) {
618
+ await app . vault . adapter . read ( indexFile . path )
619
+ meta = app . metadataCache . getFileCache ( indexFile ) ;
620
+ }
621
+ Object . assign ( siteConfig , meta ?. frontmatter || { } ) ;
606
622
log . info ( 'site meta: ' , siteConfig ) ;
607
623
}
608
624
0 commit comments