What does the parseFrontMatterAliases() function do?

Hello, here I am looking again at possibly trying to learn Obsidian plugin development. It’s a slog! :slight_smile: Part of what I’ll need to do is get a list of all task items in my vault, which I can modify and “put back” somehow according to my vague plans. See how little I know? :smile:

In the process, I was looking at a related plugin (task-archiver) and noticed that it called the obsidian API function parseFrontMatterAliases(). I have no idea what this function does. So I looked around and found only this:

As impressive as that link makes things look, the documentation for this function is pretty sparse. I see it takes a “frontmatter” argument. But there is no explanation of what this might be. I have only my intuition that it represent the frontmatter of a file somehow. Is it a string? Where would I get this string from?

Thanks for any pointers to documentation. I’ve looked through for Plugin Developers - Obsidian Hub - Obsidian Publish and nothing is jumping out to help me.

Thanks!

Frontmatter is the YAML-formatted header meta-data sometimes found at the front (top) of the note. This meta-data is delineated by lines containing only three hyphens. This data takes the form of key-value pairs where the value may be a list.

As to the specific API call you ask about, I assume it will return the value(s) of the ‘alias:’ key. I.E.: if the front matter contains a line

Blockquote
alias: [ foo, bar, baz ]

Then parseFrontMatterAliases would return the array [ “foo”, “bar”, “baz” ].

Thanks for the reply!

Your assumption is perhaps right, although I also took a guess and I don’t know how to determine which guess could be right. I wonder, is there an authoritative source we could check to see? Or do developers generally just try stuff until it works? I’d like to hear from a plugin developer about this.

Cheers and thanks again

Frontmatter is simply a JavaScript object. You can get the frontmatter of a myTFile of type TFile using this.app.metadataCache.getFileCache(myTFile)?.frontmatter.

1 Like

Thank you! Can I ask, how did you come by this knowledge? By playing around in the developer’s console and using your instincts? Asking other developers? A combination? Thanks!

1 Like

Go to https://github.com/obsidianmd/obsidian-api/blob/master/obsidian.d.ts, press Ctrl+F, and search for frontmatter. Go through every instance and guess what they do.

1 Like

thank you, I’ll do that

1 Like