Skip to content

Commit

Permalink
Implemented a better link-creation mechanism.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan J.A. Murphy committed Nov 8, 2020
1 parent 045930e commit 9a46a6e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
14 changes: 8 additions & 6 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,11 @@ export default class Review extends Plugin {
if (parsedResult.moment.isValid()) {
// get the current note name
let noteName = obsidianApp.workspace.activeLeaf.getDisplayText();
let noteFile = obsidianApp.workspace.activeLeaf.view.file;
let noteLink = obsidianApp.metadataCache.fileToLinktext(noteFile, noteFile.path, true);



// check if the file exists
// check if the daily note file exists
let files = obsidianApp.vault.getFiles();
const dateFile = files.filter(e => e.name === inputDate //hat-tip 🎩 to @MrJackPhil for this little workflow
|| e.path === inputDate
Expand All @@ -90,7 +92,7 @@ export default class Review extends Plugin {
console.log("File found:" + dateFile);
if (!dateFile) { //the 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 + "[[" + noteName + "]]";
let noteText = reviewHeading + "\n" + reviewLinePrefix + "[[" + noteLink + "]]";
let newDateFile = obsidianApp.vault.create(notesPath + inputDate + ".md", noteText);
new Notice("Set note \"" + noteName + "\" for review on " + inputDate + ".");
} else { //the file exists
Expand All @@ -101,9 +103,9 @@ export default class Review extends Plugin {
console.log("Previous Note text:\n" + previousNoteText);
let newNoteText = "";
if (previousNoteText.includes(reviewHeading)) {
newNoteText = previousNoteText.replace(reviewHeading, reviewHeading + "\n" + reviewLinePrefix + "[[" + noteName + "]]\n");
newNoteText = previousNoteText.replace(reviewHeading, reviewHeading + "\n" + reviewLinePrefix + "[[" + noteLink + "]]\n");
} else {
newNoteText = previousNoteText + "\n" + reviewHeading + "\n" + reviewLinePrefix + "[[" + noteName + "]]\n";
newNoteText = previousNoteText + "\n" + reviewHeading + "\n" + reviewLinePrefix + "[[" + noteLink + "]]\n";
}
obsidianApp.vault.modify(dateFile, newNoteText);
new Notice("Set note \"" + noteName + "\" for review on " + inputDate + ".");
Expand Down Expand Up @@ -163,7 +165,7 @@ class ReviewSettingTab extends PluginSettingTab {

containerEl.empty();

containerEl.createEl('h2', { text: 'Review settings' });
containerEl.createEl('h2', { text: 'Review Settings' });

new Setting(containerEl)
.setName('Daily note location')
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.2.1",
"version": "1.3.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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "review-obsidian",
"version": "1.0.0",
"version": "1.3.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 Down

0 comments on commit 9a46a6e

Please sign in to comment.