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( diff --git a/lib/updateBacklinks.ts b/lib/updateBacklinks.ts index 1a61242..1343c27 100644 --- a/lib/updateBacklinks.ts +++ b/lib/updateBacklinks.ts @@ -78,17 +78,29 @@ 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("")}` ) - .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; }