To use Joplin as a knowledge base it would be useful to have a “what links here”?
What do you think?
To use Joplin as a knowledge base it would be useful to have a “what links here”?
What do you think?
I think this might be quite some effort and additionally there will be ongoing maintenance required. To do this you basically have to create a separate table and maintain a source - target list. Thus every time you touch a link, maintenance has to be done on that table.
I was thinking that this could be implemented like a plugin, so every time you want backlink info a script would run over all of your notes and find backlinks. This could be slow for a lot of notes, but will otherwise work. I don’t see this being a core feature in Joplin however.
Using Python and Joplin API, I was able to add backlinks automatically. Following the script I wrote and used:
import requests, re
token="REPLACE YOUR TOKEN HERE"
resp = requests.get("http://127.0.0.1:41184/notes?token="+token+"&fields=id,title,body")
# Loop on all notes
for item in resp.json():
# Find link to note '[anything](:/anything)' in note body, excludes links start with '!' or 'backlink:'
links = re.findall("(?<=[^\!backlink:])\[.*\]\(:\/.*\)", item['body'])
# If list 'links' is not empty
if links:
# Loop on links
for link in links:
# Get target node id
target_node_id = re.search(r"\(:\/(.*)\)",link)
# Get target node body
output_dict = [x for x in resp.json() if x['id'] == target_node_id.group(1)]
# Add backlink at the end of the target node body
new_body={"body": output_dict[0]['body']+'\n* * *\n'+'backlink:[{}](:/{})'.format(item['title'], item['id'])}
# Update target node
update_resp = requests.put('http://127.0.0.1:41184/notes/'+target_node_id.group(1)+"?token="+token,json=new_body)
P.S.
backlink:
before the backlink, that’s to avoid backlinks endless cycle. You can change it though in the code before first run.2 problems still:
I just thought I will post this initial code, may someone would like to pick it up and resolve above 2 issues and improve it.
Are you saying links (and hence backlinks) are not primary citizens in Joplin? So I should organize my notes in a hierarchy, rather than link relevant pieces?
Okay, new idea here.
To implement “What links here” you just need one thing: the id of the note.
Proposed workflow:
I think this “search for node id” is straightforward to implement, yet useful enough to consider in this form.
What do you think, @tessus and @laurent?
At first, I was thinking scripting it (as Rami stated and started)
To optimize the search
part (searching directly in the body using the API), I read (again ) the documentation and stumbled upon specifically the Field restricted
part. Yes, it's for the client (desktop or Android from what I tested) but instead of backlinks (and having to manage them), what about smart backlinks ? A syntax which would trigger a search using a note ID for instance...
Let me rephrase ...
Given 2 notes (SOURCE and TARGET),
[TARGET](:/TARGET_ID)
[Backlinks](:/search:body:TARGET_ID)
body:TARGET_ID
What do you think?
Have I missed something in the documentation?