Added Feature - Daily note summary

This commit is contained in:
2025-11-22 17:01:41 +01:00
parent 6dc4d2952d
commit 951e9c5406

96
main.js
View File

@@ -44,7 +44,11 @@ var DEFAULT_SETTINGS = {
{ id: "learning", name: "Learning", color: "#f59e0b", icon: "\u{1F4DA}" }
],
autoStartBreak: false,
tickSoundEnabled: false
tickSoundEnabled: false,
// Daily note logging
logToDaily: false,
dailyNoteFormat: "YYYY-MM-DD",
dailyNoteHeading: "## \u26A1 Completed Tasks"
};
var DEFAULT_DATA = {
tasks: [],
@@ -640,6 +644,9 @@ var FocusTaskPlugin = class extends import_obsidian3.Plugin {
if (this.settings.enableSounds) {
this.playCompletionSound();
}
if (this.settings.logToDaily) {
this.logTaskToDailyNote(task);
}
if (this.activeTaskId === taskId) {
this.stopTimer();
this.activeTaskId = null;
@@ -878,6 +885,80 @@ var FocusTaskPlugin = class extends import_obsidian3.Plugin {
console.log("Audio not available");
}
}
// ============ Daily Note Logging ============
async logTaskToDailyNote(task) {
try {
const dailyNotePath = this.getDailyNotePath();
const list = this.settings.lists.find((l) => l.id === task.list);
const timeDiff = task.actualMinutes - task.estimatedMinutes;
let timeComparison = "";
if (timeDiff < 0) {
timeComparison = `${Math.abs(timeDiff)}min under estimate \u2728`;
} else if (timeDiff > 0) {
timeComparison = `${timeDiff}min over estimate`;
} else {
timeComparison = `exactly on target \u{1F3AF}`;
}
const completedTime = new Date(task.completedAt || Date.now()).toLocaleTimeString("en-US", {
hour: "2-digit",
minute: "2-digit",
hour12: false
});
const taskEntry = `- [x] ${task.text} | ${(list == null ? void 0 : list.icon) || "\u{1F4CB}"} ${(list == null ? void 0 : list.name) || "Task"} | \u23F1\uFE0F ${this.formatTimeHuman(task.actualMinutes)} / ${this.formatTimeHuman(task.estimatedMinutes)} (${timeComparison}) | \u2705 ${completedTime}`;
await this.appendToDailyNote(dailyNotePath, taskEntry);
} catch (e) {
console.error("Failed to log task to daily note:", e);
new import_obsidian3.Notice("Failed to log task to daily note");
}
}
getDailyNotePath() {
const now = new Date();
const format = this.settings.dailyNoteFormat;
const year = now.getFullYear();
const month = (now.getMonth() + 1).toString().padStart(2, "0");
const day = now.getDate().toString().padStart(2, "0");
let filename = format.replace("YYYY", year.toString()).replace("MM", month).replace("DD", day);
return `${filename}.md`;
}
async appendToDailyNote(path, content) {
const { vault } = this.app;
const heading = this.settings.dailyNoteHeading;
let file = vault.getAbstractFileByPath(path);
if (!file) {
await vault.create(path, `# ${new Date().toLocaleDateString("en-US", { weekday: "long", year: "numeric", month: "long", day: "numeric" })}
${heading}
${content}
`);
new import_obsidian3.Notice("\u{1F4DD} Task logged to new daily note");
return;
}
if (!(file instanceof import_obsidian3.TFile)) {
new import_obsidian3.Notice("Daily note path is not a file");
return;
}
let existingContent = await vault.read(file);
if (existingContent.includes(heading)) {
const headingIndex = existingContent.indexOf(heading);
const afterHeading = headingIndex + heading.length;
const nextHeadingMatch = existingContent.slice(afterHeading).match(/\n##? /);
let insertPosition;
if (nextHeadingMatch && nextHeadingMatch.index !== void 0) {
insertPosition = afterHeading + nextHeadingMatch.index;
} else {
insertPosition = existingContent.length;
}
const before = existingContent.slice(0, insertPosition);
const after = existingContent.slice(insertPosition);
const newContent = before.trimEnd() + "\n" + content + "\n" + after.trimStart();
await vault.modify(file, newContent);
} else {
const newContent = existingContent.trimEnd() + "\n\n" + heading + "\n\n" + content + "\n";
await vault.modify(file, newContent);
}
new import_obsidian3.Notice("\u{1F4DD} Task logged to daily note");
}
// ============ Utilities ============
formatTime(seconds) {
const absSeconds = Math.abs(seconds);
@@ -985,6 +1066,19 @@ var FocusTaskSettingTab = class extends import_obsidian3.PluginSettingTab {
this.plugin.settings.enableCelebrations = value;
await this.plugin.saveAllData();
}));
containerEl.createEl("h2", { text: "\u{1F4DD} Daily Note Integration" });
new import_obsidian3.Setting(containerEl).setName("Log completed tasks to daily note").setDesc("When you complete a task, add an entry to your daily note").addToggle((toggle) => toggle.setValue(this.plugin.settings.logToDaily).onChange(async (value) => {
this.plugin.settings.logToDaily = value;
await this.plugin.saveAllData();
}));
new import_obsidian3.Setting(containerEl).setName("Daily note filename format").setDesc("Format for daily note filename (YYYY = year, MM = month, DD = day)").addText((text) => text.setPlaceholder("YYYY-MM-DD").setValue(this.plugin.settings.dailyNoteFormat).onChange(async (value) => {
this.plugin.settings.dailyNoteFormat = value || "YYYY-MM-DD";
await this.plugin.saveAllData();
}));
new import_obsidian3.Setting(containerEl).setName("Section heading").setDesc("Heading under which completed tasks will be logged").addText((text) => text.setPlaceholder("## \u26A1 Completed Tasks").setValue(this.plugin.settings.dailyNoteHeading).onChange(async (value) => {
this.plugin.settings.dailyNoteHeading = value || "## \u26A1 Completed Tasks";
await this.plugin.saveAllData();
}));
containerEl.createEl("h2", { text: "\u{1F4CB} Lists" });
this.plugin.settings.lists.forEach((list, index) => {
new import_obsidian3.Setting(containerEl).setName(`${list.icon} ${list.name}`).addText((text) => text.setValue(list.name).setPlaceholder("List name").onChange(async (value) => {