Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for frontmatter links. Requires obsidian v1.4.0+. #2030

Merged
merged 4 commits into from
Sep 15, 2023

Conversation

rocketnova
Copy link
Contributor

Issues

Changes

  • Adds frontmatter links to file.outlinks and file.inlinks
  • Sets the minimum obsidian dependency version at least v.1.4.0

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 (if propertly quoted). These links are not added to the .links property in CachedMetadata. Instead they are added as a new and separate property called .frontmatterLinks.

I believe that my change of adding the CachedMetadata.frontmatterLinks to PageMetadata.links resolves the issues described in #2019 and #2029 where file.outlinks and file.inlinks do not include links added to notes in yaml frontmatter using the new Properties functionality.

Note about the API

The web API docs are out of date. You can see the update to the CachedMetadata class in the latest API source code was added in v1.4.0 and is documented in the changelog.

Other impacts

I ran npm run test and all the tests pass, but I'm not sure if there are other concerns with either of these changes (i.e. updating the minimum dependency version and adding frontmatter links to file.outlinks and file.inlinks. I could definitely use some advice from the maintainers and/or core contributors on this.

Testing

You can test this out by doing the following.

Verify that frontmatter links are not included in file.inlinks and file.outlinks without this patch:

  1. Update to Obsidian 1.4.5
  2. Create a new note and add a frontmatter link using the new Properties interface to an existing note (or you can also just do something like myprop: "[[existing note]]" in source code mode if you don't want to use the Properties interface)
  3. Create a dataview that looks something like this and verify that the outcome is that no outlinks are displayed:
LIST file.outlinks
WHERE file.name = "<new note name>"
  1. Create a dataview that looks something like this and verify that the outcome is that no inlinks are displayed:
LIST file.inlinks
WHERE file.name = "<the note you linked to>"

Verify that frontmatter links are included in file.inlinks and file.outlinks with this patch:

  1. Update to Obsidian 1.4.5
  2. Update the Dataview plugin to use this branch. Make sure to run npm install to update the dependencies
  3. The above dataviews should now render links

@rocketnova
Copy link
Contributor Author

Thanks for triggering the CI jobs for my branch.

I ran npm run format to run prettier and I think that should fix the code formatting failure. But when I run npm run build locally, I don't get any typechecking errors. Could you re-run the CI job and see if it still errors out?

@AB1908
Copy link
Collaborator

AB1908 commented Sep 6, 2023

Interestingly, tests pass so I can only assume we're missing some sort of test coverage.

@AB1908
Copy link
Collaborator

AB1908 commented Sep 6, 2023

This is somewhat beyond my ability so let's see if the author comments. :)

@lomky
Copy link

lomky commented Sep 15, 2023

The build fail is also happening in the master branch, but PR #2021 already addresses it

@rocketnova
Copy link
Contributor Author

I believe I have addressed the failing CI jobs! Could a maintainer please approve the CI job run for this PR?

@blacksmithgu blacksmithgu merged commit f12261b into blacksmithgu:master Sep 15, 2023
3 checks passed
@blacksmithgu
Copy link
Owner

Huh, there is a new metadata.frontmatterLinks. Interesting!

@KiljanK
Copy link

KiljanK commented Sep 15, 2023

Hey, thanks for all you do :)

Is there any estimate on when these fixes will be available in obsidian, or is downloading this repo and adding the plugin manually the best option for now?

@AB1908
Copy link
Collaborator

AB1908 commented Sep 15, 2023

I don't know how to cut releases but I think we should push something out on BRAT

@blacksmithgu
Copy link
Owner

blacksmithgu commented Sep 15, 2023

I just cut release 0.5.57 which includes this and many other community PRs. I did a bit of testing where the feature appears to work!

@KiljanK
Copy link

KiljanK commented Sep 15, 2023

I cannot thank you enough! I immediately went ahead and updated and it seems to have fixed the issue i was having (it was messing with some frontmatter links in the leaflet plugin)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants