Robin-Haupt-1 / Obsidian-Map-of-Content

Generate and display a Map of Content for your Obsidian vault that gets updated with any changes, based on the links in your vault
GNU General Public License v3.0
171 stars 5 forks source link

Support Properties links (frontmatter links) added in Obsidian 1.4.5 #110

Closed rocketnova closed 1 year ago

rocketnova commented 1 year ago

Changes

Context

The new Obsidian 1.4.5 release added a new feature called Properties. One of the things it does is add support wiki-style links (e.g. [[]]) in the yaml frontmatter. These links are not added to the .links property in CachedMetadata. Instead they are added as a new and separate property called .frontmatterLinks.

I think that the code for building the list of links could probably get tidied a little bit by using a Set instead of an array for all_links since it would naturally handle the de-duplication safety check, but I didn't want to exceed the scope of the problem, which is just to get frontmatter links into all_links.

Testing

You can test this out by doing the following.

Verify that frontmatter links are not considered without this patch:

  1. Update to Obsidian 1.4.5
  2. Make sure there is a central note set in the Map of Content plugin settings
  3. Create a new note
  4. Add a property to the new note and add a link to the central note
  5. On the new note, the Map of Content viewer should show no connections to the central note

Verify that frontmatter links are considered with this patch:

  1. Update to Obsidian 1.4.5
  2. Update the Map of Content plugin to use this branch
  3. Create a new note
  4. Add a property to the new note and add a link to the central note
  5. On the new note, the Map of Content viewer should the connections to the central note

Note about the API

The new property is visible in the Obsidian Developer Console, even if it isn't yet documented in the web API docs. Here are some screenshots of what is currently shown in the API docs (apparently incorrect or incomplete) and what you can see in the Obsidian Developer Console.

Screenshot from 2023-09-02 11-00-12 Screenshot from 2023-09-02 11-01-41

rocketnova commented 1 year ago

JFYI: While working on a PR for another plugin, I found the source of truth for the obsidian API. Here's the change in the Obsidian CachedMetadata class.

lomky commented 1 year ago

Bug: Map of Content does not invoke Update Map of Content on file switch when a new properties link is added

To Reproduce:

Also reproduced with:

Robin-Haupt-1 commented 1 year ago

Thank you for contributing :+1:

rocketnova commented 1 year ago

Thanks for the quick turnaround and thanks for a very useful plugin!

Robin-Haupt-1 commented 1 year ago

You're welcome! I've also fixed the issue with frontmatter links not triggering an MOC update on note change. It will be fixed with the next release. I'm currently in the process of refactoring the codebase, using camelcase everywhere, using things like sets where useful and no longer using the obsoleted workspace.activeLeaf. Once that's done and tested, i'll release it all. Please feel free to make further suggestion towards improving the code quality or adding features.

rocketnova commented 1 year ago

I saw that! Looks great.

Robin-Haupt-1 commented 1 year ago

Release is out now