From d5ede3fc46ddba4c9dafb34e67d33a77995140a1 Mon Sep 17 00:00:00 2001 From: Tarique Sani Date: Wed, 27 Nov 2024 10:47:58 +0530 Subject: [PATCH] first release --- main.ts | 50 ++++++++++++++++++++++++++++++-------------------- manifest.json | 9 +++------ 2 files changed, 33 insertions(+), 26 deletions(-) diff --git a/main.ts b/main.ts index 40e0fe9..0d849ca 100644 --- a/main.ts +++ b/main.ts @@ -72,33 +72,38 @@ export default class MergeDailyNotesPlugin extends Plugin { this.settings.mergePath ).open(); } - async mergeDailyNotes(startDate: string, endDate: string, selectedFile: string) { + async mergeDailyNotes( + startDate: string, + endDate: string, + selectedFile: string + ) { // Save the selected dates in settings this.settings.lastStartDate = startDate; this.settings.lastEndDate = endDate; await this.saveSettings(); - - const dailyNotesPlugin = this.app.internalPlugins.getPluginById("daily-notes"); - + + const dailyNotesPlugin = + this.app.internalPlugins.getPluginById("daily-notes"); + if (!dailyNotesPlugin || !dailyNotesPlugin.enabled) { new Notice("Daily Notes plugin is not enabled."); return; } - + const settings = dailyNotesPlugin.instance.options; const folder = settings.folder; const dateFormat = settings.format; - + const start = moment(startDate, "YYYY-MM-DD"); const end = moment(endDate, "YYYY-MM-DD"); - + const vault = this.app.vault; const mergePath = this.settings.mergePath; - + await vault.createFolder(mergePath).catch(() => {}); // Ensure the folder exists - + let outputFile: TFile | null = null; - + // Handle file selection logic if (selectedFile === "new") { const outputPath = `${mergePath}/${startDate} to ${endDate}.md`; @@ -110,44 +115,49 @@ export default class MergeDailyNotesPlugin extends Plugin { return; } } - + let currentDate = start.clone(); while (currentDate.isSameOrBefore(end)) { const fileName = `${folder}/${currentDate.format(dateFormat)}.md`; const file = vault.getAbstractFileByPath(fileName); - + if (file) { let content = await vault.read(file); - + // Apply stripping settings if (this.settings.stripFrontMatter) { content = content.replace(/^---[\s\S]*?---\n/, ""); } - + if (this.settings.stripCodeBlocks) { content = content.replace(/```[\s\S]*?```/g, ""); // Regex for multiline blocks } - + // Append the formatted content to the output file await vault.append( outputFile, - `## ${currentDate.format("YYYY-MM-DD")}\n\n${content}\n\n---\n\n` + `## ${currentDate.format( + "YYYY-MM-DD" + )}\n\n${content}\n\n---\n\n` ); } - + currentDate.add(1, "days"); } - + new Notice(`Daily notes merged and saved to: ${outputFile.path}`); } - } // Modal for date selection class DatePickerModal extends Modal { constructor( app: App, - private onSubmit: (startDate: string, endDate: string, selectedFile: string) => void, + private onSubmit: ( + startDate: string, + endDate: string, + selectedFile: string + ) => void, private defaultStartDate: string, private defaultEndDate: string, private mergePath: string diff --git a/manifest.json b/manifest.json index f817c2f..2ed5137 100644 --- a/manifest.json +++ b/manifest.json @@ -1,11 +1,8 @@ { "id": "obsidian-merge-dailynotes", "name": "Obsidian Merge Daily Notes", - "version": "1.0.0", - "minAppVersion": "0.15.0", - "description": "Demonstrates some of the capabilities of the Obsidian API.", - "author": "Obsidian", - "authorUrl": "https://obsidian.md", - "fundingUrl": "https://obsidian.md/pricing", + "version": "v1.0.0", + "description": "Merge daily notes based on given start and end date", + "author": "Tarique Sani", "isDesktopOnly": false }