TomWright / dasel

Select, put and delete data from JSON, TOML, YAML, XML and CSV files with a single tool. Supports conversion between formats and can be used as a Go package.
https://daseldocs.tomwright.me
MIT License
4.98k stars 115 forks source link

Frontmatter Support #161

Open lumenpink opened 2 years ago

lumenpink commented 2 years ago

Is your feature request related to a problem? Please describe. Frontmatter is wide used standard to add metadata usually in YAML format to markdown files. It is used in a variety of Static Site Generators like Jekill and Hugo. The format is very simple as a put the YAML between '---' in the init of de markdown file. But, for use it with dasel, first I've to extract the YAML with sed/awk before. And rewrite the header become very hard.

Describe the solution you'd like I would like that dasel supports frontmatter.

Describe alternatives you've considered To use it now I have to extract the from the header.

Additional context https://jekyllrb.com/docs/front-matter/

TomWright commented 2 years ago

Thank you for your suggestion. I'm open to supporting this but won't have time to get started for at least a week and a half due to work and holiday.

I'll think about an implementation pattern and get started when I'm back.

lumenpink commented 2 years ago

Thanks! Have a nice holiday!

TomWright commented 2 years ago

I'm considering allowing dasel to deal with multiple formats within a single file by allowing comma separated r, w and p flags.

This would then allow you to read the yaml + json document into a single dasel execution and output in the same way.

lumenpink commented 2 years ago

That's an awesome idea!

mortya commented 1 year ago

Note that this is a bigger problem than just Frontmatter. YAML generally supports multiple documents in one file. This feature is commonly used by a number of tools, especially in kubernetes. It's supported by yq. The current "dasel" parser does the wrong thing when presented with a multi-document yaml. I'll open a separate, more generic bug on this.