@@ -38,12 +38,14 @@ export class HTMLGenerator {
3838 public static async beginBatch ( plugin : InvioPlugin , exportingFiles : TFile [ ] ) {
3939 GlobalDataGenerator . clearGraphCache ( ) ;
4040 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 ) ;
4343 ( f as TFileWithMeta ) . sort = pageConfig ?. sort || 0
4444 return f ;
4545 } )
46- GlobalDataGenerator . getFileTree ( files ) ;
46+ Promise . all ( filePromises ) . then ( files => {
47+ GlobalDataGenerator . getFileTree ( files ) ;
48+ } )
4749 await StatsView . activateStatsView ( plugin ) ;
4850 const view = StatsView . getStatsView ( plugin , 'SyncingStats' ) ;
4951 await AssetHandler . updateAssetCache ( view ) ;
@@ -56,13 +58,16 @@ export class HTMLGenerator {
5658 }
5759
5860 // 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+ } )
6671 }
6772
6873 // rootPath is used for collecting context nodes
@@ -94,13 +99,13 @@ export class HTMLGenerator {
9499
95100 // inject outline
96101 if ( InvioSettingTab . settings . includeOutline ) {
97- let headerTree = LinkTree . headersFromFile ( file . markdownFile , 1 ) ;
102+ let headerTree = await LinkTree . headersFromFile ( file . markdownFile , 1 ) ;
98103 let outline : HTMLElement | undefined = this . generateHTMLTree ( headerTree , usingDocument , "Table Of Contents" , "outline-tree" , false , 1 , 2 , InvioSettingTab . settings . startOutlineCollapsed ) ;
99104 rightSidebar . appendChild ( outline ) ;
100105 }
101106
102107 // inject icon and title
103- const config = this . getMeta ( file ) ;
108+ const config = await this . getMeta ( file ) ;
104109 const pageTitle = config ?. title || app . vault . getName ( ) ;
105110
106111 let brandHeader = this . generateBrandHeader ( usingDocument , config . brand , config . icon , config . slogan , config ?. home ) ;
@@ -389,8 +394,7 @@ export class HTMLGenerator {
389394 }
390395
391396 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 ) ;
394398 log . info ( 'get file metadata: ' , pageConfig , remoteDomain ) ;
395399 log . info ( 'head with remote domain: ' , remoteDomain ) ;
396400 let pageTitle = file . markdownFile . basename ;
@@ -583,26 +587,38 @@ export class HTMLGenerator {
583587 }
584588 } )
585589 }
586-
587-
588590 }
589591
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 ;
592599 return pageConfig ;
593600 }
594- private static getMeta ( file : ExportFile ) : IMetaConfig {
601+ private static async getMeta ( file : ExportFile ) : Promise < IMetaConfig > {
595602 // Get site config
596603 const indexPath = file . exportedFolder . joinString ( 'index.md' ) ;
597604 const indexFile = app . vault . getAbstractFileByPath ( indexPath . asString ) ;
598605
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 ;
600612 log . info ( 'page config: ' , pageConfig ) ;
601613
602614 const siteConfig : IMetaConfig = { } ;
603615 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 || { } ) ;
606622 log . info ( 'site meta: ' , siteConfig ) ;
607623 }
608624
0 commit comments