sveltia / sveltia-cms

Alternative to Netlify/Decap CMS. Fast, lightweight, Git-based headless CMS. Modern UX, first-class i18n support, open source & free. Made with Svelte.
MIT License
727 stars 33 forks source link

YAML: support '<<' (merge key) #133

Closed josineto closed 2 months ago

josineto commented 2 months ago

In the configuration file, it's very useful to use YAML node anchors (e.g. &date, referenced later as *date) to ease reading and avoid repetition. But another YAML feature, the merge key (<<, used as <<: *date to merge content from *date with the current field), seems to not be supported by the Sveltia CMS' YAML parser.

Whenever I use <<, loading an entry yelds an error: "sveltia-cms.js:37 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'replace')". If I use << inside a field that itself is referenced by an anchor, there's no error in the console, but the field is created as a generic required string field regardless of its configuration.

There's a question in Stack Overflow about the merge key. It seems to be optional to parsers to support it, but I think it greatly simplifies the config file.

kyoshino commented 2 months ago

I could replace the YAML parser. Let’s see.

kyoshino commented 2 months ago

https://eemeli.org/yaml/#schema-options

Merge keys are a YAML 1.1 feature that is not a part of the 1.2 spec.

So feature-wise it’s deprecated but can be enabled using the merge: true option. I can do it a quick.

kyoshino commented 2 months ago

Just shipped v0.21.2 with merge: true!