From 2dfcb0d35c2a3d76cd0b39e1d20ee917d903021c Mon Sep 17 00:00:00 2001 From: Aaron Jensen Date: Sat, 29 Aug 2020 10:01:25 -0700 Subject: [PATCH 1/3] Backlink insertion is idempotent Prior to this, there was no newline between the text prior to the backlinks which caused it to not properly detect the backlink section. --- lib/updateBacklinks.ts | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/updateBacklinks.ts b/lib/updateBacklinks.ts index 1a61242..772801a 100644 --- a/lib/updateBacklinks.ts +++ b/lib/updateBacklinks.ts @@ -82,13 +82,23 @@ export default function updateBacklinks( ) .join("")}` ) - .join("")}\n`; + .join("")}`.trim(); } - const newNoteContents = - noteContents.slice(0, insertionOffset) + - backlinksString + - noteContents.slice(oldEndOffset); + let newNoteContents = noteContents; + + if (backlinksString) { + let end = noteContents.slice(oldEndOffset).trim() + + if (end) { + end = `\n${end}\n`; + } + + newNoteContents = + noteContents.slice(0, insertionOffset).trimEnd() + "\n\n" + + backlinksString + "\n" + + end + } return newNoteContents; } From f0cd63cc3fcf8afff9254ce3d6e3e117ad6aa1c3 Mon Sep 17 00:00:00 2001 From: Aaron Jensen Date: Mon, 31 Aug 2020 09:17:29 -0700 Subject: [PATCH 2/3] Markdown files that start with _ are ignored --- lib/readAllNotes.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/readAllNotes.ts b/lib/readAllNotes.ts index 70ab853..b8ee52c 100644 --- a/lib/readAllNotes.ts +++ b/lib/readAllNotes.ts @@ -46,7 +46,7 @@ export default async function readAllNotes( withFileTypes: true }); const notePaths = noteDirectoryEntries - .filter(entry => entry.isFile() && !entry.name.startsWith(".") && entry.name.endsWith(".md")) + .filter(entry => entry.isFile() && !entry.name.startsWith(".") && entry.name.endsWith(".md") && !entry.name.startsWith("_")) .map(entry => path.join(noteFolderPath, entry.name)); const noteEntries = await Promise.all( From 04b754da43102830c627de49603520eb18e84976 Mon Sep 17 00:00:00 2001 From: Aaron Jensen Date: Thu, 6 May 2021 20:49:11 -0500 Subject: [PATCH 3/3] Spaces, rather than tabs --- lib/updateBacklinks.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/updateBacklinks.ts b/lib/updateBacklinks.ts index 772801a..1343c27 100644 --- a/lib/updateBacklinks.ts +++ b/lib/updateBacklinks.ts @@ -78,7 +78,7 @@ export default function updateBacklinks( entry => `* [[${entry.sourceTitle}]]\n${entry.context .map( - block => `\t* ${processor.stringify(block).replace(/\n.+/, "")}\n` + block => ` * ${processor.stringify(block).replace(/\n.+/, "")}\n` ) .join("")}` ) @@ -88,16 +88,18 @@ export default function updateBacklinks( let newNoteContents = noteContents; if (backlinksString) { - let end = noteContents.slice(oldEndOffset).trim() + let end = noteContents.slice(oldEndOffset).trim(); if (end) { end = `\n${end}\n`; } newNoteContents = - noteContents.slice(0, insertionOffset).trimEnd() + "\n\n" + - backlinksString + "\n" + - end + noteContents.slice(0, insertionOffset).trimEnd() + + "\n\n" + + backlinksString + + "\n" + + end; } return newNoteContents;