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

Header: Allow to use a string list, for frontmatter key. Use the {{syntax}} to recognize key #126

Merged
merged 12 commits into from
Sep 29, 2023

Conversation

Mara-Li
Copy link
Contributor

@Mara-Li Mara-Li commented Sep 20, 2023

feat(header): use a list for banner_header, allowing to use frontmatter keys

Support list and string.

  • For list: Use the first key found in the list. Otherwise, join the list with a space.
  • For string, replace the {{key}}, allowing to combine keys and simple value.

Key supported:

  • {{file}} : Use basename
  • {{anykey}} : use this key if exists. If the key is an array, use the first.

Note

For alias, automatically convert to aliases because Obsidian convert automatically this key if it's a string.

Also added new settings:

  • Use the filename as default
  • Set a property key

See #125

…er keys

- {{aliases}} : Use first alias
- {{file}} : Use basename
- {{anykey}} : use this key if exists
Else, return the list join by space
@Mara-Li Mara-Li changed the title feat(header): use a list for banner_header, allowing to use frontmatt… Header: Allow to use a string list, for frontmatter key. Use the {{syntax}} to recognize key Sep 20, 2023
@Mara-Li
Copy link
Contributor Author

Mara-Li commented Sep 28, 2023

If anyone is interested, you can try my PR using the release !
https://github.com/Lisandra-dev/obsidian-banners/releases/tag/2.0.2-beta

@noatpad
Copy link
Owner

noatpad commented Sep 28, 2023

Pardon the delay, had an exam week, ahah.

So I moved around a few things, but in a nutshell:

  • I moved the logic to transformers.ts since in hindsight, it makes sense to keep that logic together there at the level where the YAML is turned into relevant banner data.
  • Because of possible incompatibilities for future Obsidian releases (Type Mismatch on "banner_header" key #121), the header property can't be of different types, so it has to remain a text/string property. As a compromise, I implemented the ability to add multiple fields within the curly braces that can act as fallbacks (so something like {{author, title, filename}}). It's a bit more flexible this way as a result too.
  • Reworded a few settings for clarity
  • Empty/null values work differently though. Empty text properties (ie null values) are now treated as empty in favor of {{filename}}. This is because it can act as an override to the "Display header by default" setting

Do tell if this may still present issues!

@Mara-Li
Copy link
Contributor Author

Mara-Li commented Sep 29, 2023

Hello! Thanks for the reply <3 you have better idea than me!

I added just a little information in the settings about the {{property, property2, filename}} fallback syntax!

@noatpad noatpad merged commit c836446 into noatpad:master Sep 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants