Skip to content

Commit

Permalink
fix extra date formats
Browse files Browse the repository at this point in the history
  • Loading branch information
laughedelic committed Nov 12, 2024
1 parent a05a4b2 commit 2dd2ff3
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions outbreak.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -111,15 +115,15 @@ 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;

// 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)
Expand Down Expand Up @@ -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: [
Expand Down

0 comments on commit 2dd2ff3

Please sign in to comment.