@@ -181,6 +181,7 @@ class Paster {
181181
182182 /**
183183 * Returns the first matching image rule (if any) based on the current Markdown file path.
184+ * Preprocesses variables (including timestamp) once and reuses them in both targetPath and linkPattern.
184185 */
185186 private static getMatchingImageRule ( ) : any {
186187 const config = Paster . getConfig ( ) ;
@@ -193,7 +194,19 @@ class Paster {
193194 if ( rule . match ) {
194195 const re = new RegExp ( rule . match , rule . options || "" ) ;
195196 if ( re . test ( currentFilePath ) ) {
196- return rule ;
197+ // Generate all variables (including timestamp) here
198+ const processedRule = { ...rule } ;
199+ if ( processedRule . targetPath ) {
200+ processedRule . targetPath = Predefine . replacePredefinedVars (
201+ processedRule . targetPath
202+ ) ;
203+ }
204+ if ( processedRule . linkPattern ) {
205+ processedRule . linkPattern = Predefine . replacePredefinedVars (
206+ processedRule . linkPattern
207+ ) ;
208+ }
209+ return processedRule ;
197210 }
198211 }
199212 }
@@ -221,7 +234,7 @@ class Paster {
221234 const rule = Paster . getMatchingImageRule ( ) ;
222235 if ( rule && rule . targetPath ) {
223236 let targetPattern = rule . targetPath ;
224- targetPattern = Predefine . replacePredefinedVars ( targetPattern ) ;
237+ // targetPattern is already processed in getMatchingImageRule
225238 // If the rule's pattern does not include an extension, append it.
226239 if ( path . extname ( targetPattern ) === "" ) {
227240 targetPattern += extension ;
@@ -282,7 +295,7 @@ class Paster {
282295 if ( rule && rule . linkPattern ) {
283296 const altText = Paster . getAltText ( ) ;
284297 let link = rule . linkPattern ;
285- link = Predefine . replacePredefinedVars ( link ) ;
298+ // linkPattern is already processed in getMatchingImageRule
286299 // Replace custom placeholders.
287300 link = link
288301 . replace ( / \$ \{ i m a g e F i l e P a t h \} / g, imageFilePath )
0 commit comments