Skip to content

Commit

Permalink
Thanks to @liamcain, Review now uses the daily note template (if you'…
Browse files Browse the repository at this point in the history
…ve defined one).
  • Loading branch information
Ryan J.A. Murphy committed Nov 21, 2020
1 parent 7cacdc0 commit b7e927f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
18 changes: 14 additions & 4 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { App, ButtonComponent, Modal, Notice, Plugin, PluginSettingTab, Setting, TextComponent } from 'obsidian';
import { createDailyNote } from 'obsidian-daily-notes-interface';

export default class Review extends Plugin {
settings: ReviewSettings;
Expand Down Expand Up @@ -89,7 +90,7 @@ export default class Review extends Plugin {
return blockString;
}

setReviewDate(someDate: string, someBlock?: string) {
async setReviewDate(someDate: string, someBlock?: string) {
let obsidianApp = this.app;
let naturalLanguageDates = obsidianApp.plugins.getPlugin('nldates-obsidian'); // Get the Natural Language Dates plugin.

Expand Down Expand Up @@ -162,9 +163,18 @@ export default class Review extends Plugin {
if (!dateFile) { //the date file does not already exist
console.log("The daily note for the given date does not exist yet. Creating it, then appending the review section.")
let noteText = reviewHeading + "\n" + reviewLinePrefix + "[[" + noteLink + "]]";
let newDateFile = obsidianApp.vault.create(notesPath + inputDate + ".md", noteText);
// let newDateFile = obsidianApp.vault.create(notesPath + inputDate + ".md", noteText); //previous approach
let newDateFile = await createDailyNote(parsedResult.moment); // Use @liamcain's obsidian-daily-notes-interface to create a daily note with core-defined templates
let templateText = await obsidianApp.vault.read(newDateFile);
//console.log(templateText); // for debugging
if (templateText.includes(reviewHeading)) {
noteText = templateText.replace(reviewHeading, noteText);
} else {
noteText = templateText + "\n" + noteText;
}
obsidianApp.vault.modify(newDateFile, noteText);
new Notice("Set note \"" + noteName + "\" for review on " + inputDate + ".");
} else { //the file exists
} else {
console.log("The daily note already exists for the date given. Adding this note to it for review.")
let previousNoteText = "";
obsidianApp.vault.read(dateFile).then(function (result) { // Get the text in the note. Search it for ## Review and append to that section. Else, append ## Review and the link to the note for review.
Expand All @@ -179,7 +189,7 @@ export default class Review extends Plugin {
obsidianApp.vault.modify(dateFile, newNoteText);
new Notice("Set note \"" + noteName + "\" for review on " + inputDate + ".");
});
}
}
} else {
new Notice("You've entered an invalid date (note that \"two weeks\" will not work, but \"in two weeks\" will). The note was not set for review. Please try again.");
}
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "review-obsidian",
"name": "Review",
"version": "1.5.1",
"version": "1.6.0",
"description": "Add a link to the current note to a daily note on a future date (or a past date, you time traveller).",
"author": "ryanjamurphy",
"authorUrl": "https://axle.design",
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "review-obsidian",
"version": "1.5.1",
"version": "1.6.0",
"description": "Add a link to the current note to a daily note on a future date (or a past date, you time traveller).",
"main": "main.js",
"repository": "ryanjamurphy/review-obsidian",
Expand All @@ -20,5 +20,8 @@
"rollup": "^2.32.1",
"tslib": "^2.0.3",
"typescript": "^4.0.3"
},
"dependencies": {
"obsidian-daily-notes-interface": "^0.1.0"
}
}

0 comments on commit b7e927f

Please sign in to comment.