@@ -174,16 +174,31 @@ export const RecursiveAppendDuplicateFileMacros = (
174174 if ( ! jsonSiblings ) {
175175 return ;
176176 }
177-
178177 for ( const sibling of jsonSiblings ) {
179- if ( sibling . duplicate && sibling . macros ) {
178+ if ( sibling . macros ) {
179+ // TEMP?
180+ addMColon ( sibling . macros ) ;
181+
182+ // Substitute macros into the filename
183+ const filename =
184+ sibling . file && sibling . macros
185+ ? substituteMacrosIntoFilename ( sibling . file , sibling . macros )
186+ : sibling . file ;
187+
188+ // Match against unresolved filename
180189 const matchingFileKey = Object . keys ( fileMap ) . find (
181190 key => fileMap [ key ] . file === sibling . file
182191 ) ;
183192 if ( matchingFileKey ) {
184- fileMap [ matchingFileKey ] . macros = fileMap [ matchingFileKey ] . macros
185- ? [ ...fileMap [ matchingFileKey ] . macros , sibling . macros ]
186- : [ sibling . macros ] ;
193+ // Replace with resolved filename
194+ fileMap [ matchingFileKey ] . file = filename ;
195+
196+ if ( sibling . duplicate ) {
197+ // Attach macros
198+ fileMap [ matchingFileKey ] . macros = fileMap [ matchingFileKey ] . macros
199+ ? [ ...fileMap [ matchingFileKey ] . macros , sibling . macros ]
200+ : [ sibling . macros ] ;
201+ }
187202 }
188203 }
189204
@@ -215,3 +230,22 @@ export const buildUrlId = (
215230 const urlId = `${ idPrefix } ${ idPrefix === "" ? "" : "+" } ${ fileLabel } ` ;
216231 return { urlId, fileLabel } ;
217232} ;
233+
234+ // TEMP? add colon to M macro
235+ const addMColon = ( macros : any ) => {
236+ if ( macros . M && ! macros . M . startsWith ( ":" ) ) {
237+ macros . M = ":" + macros . M ;
238+ }
239+ } ;
240+
241+ // Substitute macros into a filename
242+ const substituteMacrosIntoFilename = (
243+ filename : string ,
244+ macros : any
245+ ) : string => {
246+ let resolvedFilename = filename ;
247+ Object . entries ( macros ) . forEach ( ( [ key , value ] ) => {
248+ resolvedFilename = resolvedFilename . replace ( `$(${ key } )` , value as string ) ;
249+ } ) ;
250+ return resolvedFilename ;
251+ } ;
0 commit comments