diff --git a/outbreak.ts b/outbreak.ts index 372245e..267c1a0 100644 --- a/outbreak.ts +++ b/outbreak.ts @@ -57,17 +57,21 @@ async function readDailyNotesConfig( // Function to check if a file matches the daily notes format function isDailyNote( filePath: string, - config: ObsidianDailyNotesConfig, + dailyNotesConfig: ObsidianDailyNotesConfig, + migrationConfig: MigrationConfig, ): boolean { - const format = config.format || "YYYY-MM-DD"; - const folder = config.folder || ""; // Default to root if not specified + const format = dailyNotesConfig.format || "YYYY-MM-DD"; + const folder = dailyNotesConfig.folder || ""; // Default to root if not specified // Construct full format including the folder const fullFormat = folder ? `[${folder}]/${format}` : format; // Drop the extension const notePath = filePath.slice(0, -extname(filePath).length); // Try to parse it with moment.js (strict mode) - const parsedMoment = moment(notePath, fullFormat, true); + const parsedMoment = moment(notePath, [ + fullFormat, + ...migrationConfig.extraDailyNotesFormats, + ], true); return parsedMoment.isValid(); } @@ -111,7 +115,7 @@ function planFileMigration( ): MigrationPlan { const relativePath = relative(inputDir, inputPath); - if (isDailyNote(relativePath, dailyNotesConfig)) { + if (isDailyNote(relativePath, dailyNotesConfig, config)) { const inputFilename = basename(relativePath, extname(relativePath)); const inputFormat = basename(dailyNotesConfig.format || "YYYY-MM-DD"); const outputFormat = config.journalDateFormat; @@ -119,7 +123,7 @@ function planFileMigration( // Reformat the date string according to the configured format const parsedDate = moment(inputFilename, [ inputFormat, - ...config.extraDailyNotesFormats, + ...config.extraDailyNotesFormats.map((f) => basename(f)), ]); const reformattedDate = parsedDate.isValid() ? parsedDate.format(outputFormat) @@ -274,8 +278,8 @@ async function executeMigrationPlan( const defaultConfig: MigrationConfig = { useNamespaces: false, extraDailyNotesFormats: [ - "YYYY/YYYY-MM-DD", - "YYYY/MM/YYYY-MM-DD", + "[journal]/YYYY/YYYY-MM-DD", + "[journal]/YYYY/MM/YYYY-MM-DD", ], journalDateFormat: "YYYY-MM-DD", ignoredPaths: [