Include / show note links in yaml frontmatter (v0.8.5)

I’m not sure about what is officially planned, but I’m excited to have some sort of custom meta data that can then be used to display lists of files in a table based on that meta data.

For example, if I have all of my daily notes in a folder, I could have a meta data field of Day-(day of week)
then I could view all of the daily notes and sort/filter all notes written on a Monday.

Tracking multiple fields would also allow for some data analysis of looking at days where I do well on my habits/goals and see what factors correlate the most, etc.

2 Likes

Just want to let everyone know that YAML frontmatter is typically removed from the source code when rendering, and the variables stored are used as metadata for whichever app is reading it.

Right now we aren’t using it to store anything, but in the future, plugins would be able to access a built-in way of making decisions based on the data inside the frontmatter.

This may mean showing some UI that contains data, such as tags showing as a tag list on top of the file, or links that render as “related” somewhere else. That would be entirely customizable by the plugin and out of our control.

In the meantime, since this metadata is almost always hidden from view in other apps, we’ll be doing the same.

I do recognize the use case for some kind of user-defined front matter that’s different from what “markdown frontmatter” usually means. You can (and should) just use plain Markdown properly and do it like this:

tags: #mytag
links: [[My other file]]

---

Body content
8 Likes

This is fair enough. Now I will try to remove the start of the YAML block from many of my notes.

Can anyone help me with regex searching, so I can be sure to get all my notes?
I want to search for the string --- but only if it is the very first set of characters in the document. Otherwise my search will return every horizontal line I have ever made.

1 Like

This makes sense. Especially now that I’ve been playing around with publishing some of these markdown files.

Does this mean we wont get a sorting of files through YAML metadata like dates and such, or is it well within that realm of possibility?

1 Like

I am not sure exactly what you mean.
However, I can see a plugin implementing a sort by date and using a date stored in the YAML block.

:warning: Please, back up your notes. I can’t tell how many times I screwed up while playing with regex on multiple files at once. :warning:

I believe this will do the trick:

Find: ^(?<![\s\S\r])---\n
Replace:

I use VS Code and recommend it, but it should work on other editors.

4 Likes

That’s what I meant. I was interested in YAML, mainly for sorting purposes (among other benefits to YAML). I appreciate sorting by the date in YAML, rather than by edit time. I would have taken a sort function by creation date, but with respect to migration, I think that would screw some things up, so yeah, thats why I like the sorting by YAML idea.

Thanks, that worked great!

I would also be happy if YAML matter could nonetheless remain linkable. I use it to essentially attach file-level metadata to a note, such as major tags, authors for books, etc., as I don’t really want this information to be part of the final note, and yet I want it to be discoverable by search, the graph etc.

8 Likes

Hello!

I’m trying to figure out how to use frontmatter in my notes.

How do you use it?

2 Likes

On the top of a note, use the syntax:

---
tags: 
aliases:
whatever else you want to write:
---

to indicate frontmatter. Note that the main purpose of frontmatter is to give plugins a place to store user-readable metadata.

See the recent release notes on how to use tags and aliases. Note that these features are only available in Insider builds at this moment.

https://forum.obsidian.md/t/obsidian-release-v0-9-16-insider-build/8795

2 Likes

That’s cool.

Do you have examples of how tags and aliases are used?

I just added the functionality of updating a frontmatter in the “Markdown Prettifier” plugin. Perhaps I should take that feature out…

@WhiteNoise recommended in August to use this format

---
YAML metadata
---

your frontmatter

--- 
main text 

After all the changes in the meantime, is this still recommended, or I could put my custom attributes there like in ryan’s example above?

3 Likes

I have the same question. I also see (I think above, but I’ve got so many tabs open on this subject right now) that some will encapsulate their title not in quote marks " but double brackets [[ so that, I assume, they update with the note title changes. This works well, but it does not work in the YAML header either. Thoughts?

@ryanjamurphy, I’d love your input. (And thanks for all your contributions here and on talk.macpowerusers.com.)

1 Like

you can add your custom attributes in the YAML frontmatter but:

  • They MUST be in proper yaml format.
  • If an attribute is not handled by obsidian or plugin, it will be ignored. But still has to be YAML format.
  • There is no support (yet) for adding a linked mention to another note, that is, if NoteA has this frontmatter:
---
links: [[NoteB]], [[NoteC]]
---

It will not work. NoteA will not appear as a linked mention (backlink) in NoteB and NoteC.

  • The YAML frontmatter is not scanned when searching for unlinked mentions (and probably never will be). That is, if NoteA has this frontmatter:
---
connections: [NoteB, NoteC]
---

NoteA will not appear as an unlinked mention in NoteB and NoteC.

Addendum:
I would like to add that if at some point we add support for linking other notes in the YAML block, it will be specific and limited to a YAML attribute, like related: . But it still won’t be possible to add linked mentions in other attributes.
So if this is your intent, I think you are still better off with you own frontmatter in the document and not in the YAML block.

7 Likes

@millerstevew: thanks for the link to the mac power users site. As a 1 year old Mac novice I did not know it. Interesting stuff there.

2 Likes

First, I’d like to thank all contributors to Obsidian for making the absolute best knowledge management application!

Over the years all other applications never quite delivered and ideas of a better system started accumulating in my mind. The most notable idea being able to link anything to anything and use those links as tags themselves. Notion almost allowed this possibility, but not completely. Then Obsidian appeared, making this a reality!

As I’ve become aquatinted with Obsidian I’ve realized that many of my notes are of a particular type or kind. Let’s use Movie for example. For any note that’s a movie I can just add a [[Movie]] link to the top of my file and BAM, that link itself serves as a tag for all movies.

However, all notes that have an “is a” relationship to movie also happen to share a standard set a metadata such as director, run time, IMDB rating, etc. I also want this metadata to be links themselves. The obvious solution seems to be to create a template for Movie that I can apply to all “is a Movie” notes. This does begin to solve the problem of keeping all of the metadata standardized, but it does not solve every problem.

My next thought was for this metadata to be parsable in a way that I or someone else could build a plugin to view all notes that are a Movie in a table just like a Notion database with a standard set of properties. Then I found YAML support for Obsidian which seemed perfect! That is until I realized links do not yet work in YAML front matter. Therefore links could not also serve as the metadata entries.

I’m certainly not the only one that uses links as tags. It seems to be quite a popular trend. The other popular trend for users that use links as tags also seems to be adding links to the top of their notes that’s nearly identical to YAML front matter. This is a VERY common pattern.

TLDR

I deeply desire the option for YAML metadata to be universally link compatible. I want to build, or see built, plugins that can take advantage of YAML metadata that are also links, while at the same time Obsidian also observes them as links in the graph.

I propose that the syntax could be something like the following and just use the standard backlink formatting already used:

---
customProperty01: [notalink, randomstring]
customProperty02: [[[isalink]], [[another link]]]
customProperty03:
- notalink
- [[isalink]]
links: [NoteB, NoteC] <-- Similar to "tags", but creates links.
---
14 Likes

@pyrotecx Could you open a new #feature-requests for this? I’m afraid we won’t be able to track this in the feature archive and it will get lost.

1 Like