Skip to content

Commit 2dfcb0d

Browse files
committed
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.
1 parent 033ec23 commit 2dfcb0d

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

lib/updateBacklinks.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,23 @@ export default function updateBacklinks(
8282
)
8383
.join("")}`
8484
)
85-
.join("")}\n`;
85+
.join("")}`.trim();
8686
}
8787

88-
const newNoteContents =
89-
noteContents.slice(0, insertionOffset) +
90-
backlinksString +
91-
noteContents.slice(oldEndOffset);
88+
let newNoteContents = noteContents;
89+
90+
if (backlinksString) {
91+
let end = noteContents.slice(oldEndOffset).trim()
92+
93+
if (end) {
94+
end = `\n${end}\n`;
95+
}
96+
97+
newNoteContents =
98+
noteContents.slice(0, insertionOffset).trimEnd() + "\n\n" +
99+
backlinksString + "\n" +
100+
end
101+
}
92102

93103
return newNoteContents;
94104
}

0 commit comments

Comments
 (0)