Hey there, I made a little plugin that assigns 4-character note codes to every note in your vault.
I wanted a way to refer to my notes in hand-written journals and in other things like shell scripts, but embedding full note titles or obsidian:// URIs was rather painful. So this thing lets you just use short codes in the XX-XX format.
I tried to specifically make these easy to use for handwriting, so note codes will do things like treate similar-looking characters as one and the same, meaning that AA-0A == AA-OA.
Very interesting. Seems inspired by Luhmann’s Zettelkasten.
Though I’m disappointed by the fact that the code changes every time a note is renamed or changes location. It’d be wonderful if the code assigned to a note would be immutable. Could this be added? (There’s a long-standing feature request for this to be added to Obsidian.)
There’s also a matter of future-proofing. I would be very cautious to become reliant on such a plugin: a future Obsidian update could break the plugin’s URL scheme, and/or the plugin could stop being maintained.
For note code stability, that’s sadly a downside. I’m not really aware of a good way to handle it unfortunately. I explored two approaches. The first was to store the code in the note’s metadata, but that meant that things like attachments could not have a code attached. The second was to store the code in some separate vault-specific storage, but then the future-proofing challenge you described comes into play - there is an extra file to maintain.
As far as I’m aware, there just isn’t a good answer to the problem of attaching metadata to a file in a cross-platform, cross-file system way.
I went with what I thought would be more future-proof: just using a hash of the filename.
The nice thing about this approach is that the hash is stable, as long as the note’s name and location relative to the root of the vault does not change. This approach is also not tied to the vault in any way, so even if you just have the file path, you can figure out its note code.
My approach was to do the simplest thing using standard mechanisms - it’s just a SHA-256 hash of the name presented in a nicer manner. I figured the simplicity would be good for future-proofing here.
In fact, here is the whole algorithm in Python - pass it the path to the note relative to the vault, with file extension, UTF-8 encoded:
import hashlib
def hash_string(s):
h = hashlib.sha256(s.encode()).digest()
n = ((h[0] << 16) | (h[1] << 8) | h[2]) % (32**4)
a = '0123456789ABCDEFGHJKMNPQRSTVWXYZ'
r = ''.join(a[n // 32**(3-i) % 32] for i in range(4))
return f"{r[:2]}-{r[2:]}"