Backlink insertion is idempotent#9
Conversation
Prior to this, there was no newline between the text prior to the backlinks which caused it to not properly detect the backlink section.
|
Thanks for submitting a pull request, Aaron. I don't really understand what you're trying to do here. Could you describe in more detail please? |
|
Hi @andymatuschak, Looks like I added another commit here, which I have removed. But basically, I ran into an issue in my markdown files where note-link-janitor was not actually idempotent. It would not detect the backlink section on the second run, so it would actually treat it as content meaning it would consider links in the backlink section as backlinks, causing note-link-janitor to add recursive backlinks. I tracked it down to the fact that when it adds the The changes also normalize the newlines--they don't add an extra newline at the bottom of the file and it ensures that there's exactly 1 blank line above the backlinks section and 1 below (if there is anything below, 0 otherwise). Here is a repro demonstrating the problematic behavior with the current version: https://github.com/aaronjensen/note-link-janitor-idempotency-repro/commits/master You can review the commits in reverse order to see what happens. The second run is the erroneous one. If you run the version from this PR twice on the initial commit of that repo, it should not produce the recursive and redundant backlinks. |
Prior to this, there was no newline between the text prior to the backlinks which caused it to not properly detect the backlink section.
This perhaps isn't the cleanest implementation, but it fixes things for me. It also gets rid of the extra newline at the end of files that was previously emitted.