silverbulletmd / silverbullet

The hackable notebook
https://silverbullet.md
MIT License
2.06k stars 146 forks source link

Updating nested keys in frontmatter via snippet is broken #723

Closed gorootde closed 4 months ago

gorootde commented 4 months ago

The (https://silverbullet.md/Snippets#Frontmatter)[Snippets Documentation] states that if a frontmatter is already present, it will be combined with the one already present in the document.

This doesn't work for sub-keys and already existing keys.

Minimal Example: snippet.md

---
    tags: template
    hooks.snippet.slashCommand: add-alias
    frontmatter: |
       aliases:
          - foobar
---

page.md

---
aliases:
   - someAlias
---

page.md will only contain someAlias after applying the snippet to page.md, whereas it should contain foobar additionally.

zefhemel commented 4 months ago

Yeah, we can do some better object merging here.

zefhemel commented 4 months ago

Actually, if you use the | notation you'll include frontmatter verbatim as a string. If you pass it in as a YAML object you may get better results. You will have to make sure it's valid YAML though and therefore put quotes around directives, eg "{{something}}"

gorootde commented 4 months ago

I tried that as well. Deep merging does also not work when using a yaml object