Skip to content

Commit

Permalink
first release
Browse files Browse the repository at this point in the history
  • Loading branch information
tariquesani committed Nov 27, 2024
1 parent 999465e commit d5ede3f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 26 deletions.
50 changes: 30 additions & 20 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
Expand All @@ -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
Expand Down
9 changes: 3 additions & 6 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit d5ede3f

Please sign in to comment.