Getting backlinks, tags and frontmatter entries for a note

you can try this code in the console, it should give you all the data you need:

file = app.vault.getAbstractFileByPath("your/file.md")
metadata = app.vault.metadataCache.getFileCache(file)
backlinks = app.vault.metadataCache.getBacklinksForFile(file)

metadata contains all values except backlinks, if a file has no frontmatter for example, metadata.frontmatter will not exist.
https://github.com/obsidianmd/obsidian-api/blob/c01fc3074deeb3dfc6ee02546d113b448735b294/obsidian.d.ts#L388-L425

Tags need to be collected in two places, one is on the metadata.frontmatter.tags the tags that are placed in document are on metadata.tags.

getBacklinksForFile is not document officially, so it might break at some point.


For detecting when the active note has been changed you probably want to listen to this event: https://github.com/obsidianmd/obsidian-api/blob/c01fc3074deeb3dfc6ee02546d113b448735b294/obsidian.d.ts#L3724

4 Likes