Skip to content

Instantly share code, notes, and snippets.

@jsloat
Last active December 27, 2022 23:27
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jsloat/142aef35fd8b6fd8e6d1fbb850653558 to your computer and use it in GitHub Desktop.
Save jsloat/142aef35fd8b6fd8e6d1fbb850653558 to your computer and use it in GitHub Desktop.
Generate backlinks for Bear notes in Scriptable on iOS
@xlZeroAccesslx
Copy link

@jsloat This is awesome! Does it work with Wiki links with note headers?

E.g. [[Page Title/Header Title]]

https://blog.bear.app/2020/09/bear-1-7-15-is-out-with-new-features-for-wiki-links-html-export-and-more/

@xlZeroAccesslx
Copy link

If you change the regex from /\[\[(.+?)\]\]/g to /\[\[([\w\d\s]+)(?:\/.+|)\]\]/g on line 75 it will create backlinks for wiki links with headers references...assuming the intended behavior is to create backlinks for individual notes by ignoring the header reference.

@jsloat
Copy link
Author

jsloat commented Nov 23, 2020

@xlZeroAccesslx nice catch 👍 I have actually updated my own code to support this but didn't update here. I think your solution would probably work but I will just update the whole file with my latest version, will be up within a half hour

@jsloat
Copy link
Author

jsloat commented Nov 23, 2020

Updated version posted -- I refactored this for my devices a couple months ago so the code will look different, but the basic functionality is the same and it's backwards compatible if you've already been using it. But per usual, probably a good idea to backup your Bear database before trying :)

Only thing that was removed was the "blacklist" notes (array of note titles to exclude as link sources). I wasn't using this so I removed, but if anyone misses it I can add it back in.

The new version supports wiki links/note headers as @xlZeroAccesslx mentions above, plus some smaller tweaks that aren't really noticeable. I think this version uses less device memory so if anyone was experiencing slowness/crashes before, this may fix that.

@Torgithub
Copy link

Torgithub commented Dec 15, 2020

Great work man!

I would love if I could see some context in the backlinks as well, pulling in the paragraph were the link is mentioned.

Here is my backlinks from a page like the script is working now:

epigenetics

::METADATA::

Backlinks

  • [[S- 2020 - Who We Are - YouTube - Documentary]]

Here is how I ideally want it to look to get more context:

epigenetics

::METADATA::

Backlinks

  • [[S- 2020 - Who We Are - YouTube - Documentary]]
    • [[epigenetics]] - Control above the genes.

@jsloat
Copy link
Author

jsloat commented Jan 4, 2021

@Torgithub thanks! This is a nice idea, definitely possible. I may give this a go at some point, but probably not in the near-term.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment