RC Logr 20190307 172838
Thursday, 7 Mar, 2019
Python program «remarshal» is a useful utility to convert between TOML, YAML and JSON. My friend Bjørn wrote this one-liner to use it to convert the frontmatter of content markdown files, from TOML to YAML, because github renders them nicely. Here is his solution:
| |
Run from the root of your Hugo project, this command finds any markdown files in the content folder ending in .md, then reads each line by line into a pipeline of commands. The YAML var is set, by extracting the lines between the +++ delimiters and using remarshal to convert that TOML to YAML. Then, perl is used to find the whole frontmatter section including the +++ lines, and replace that with the $YAML variable contents, between --- delimiters expected for YAML frontmatter. (Why doesn’t Github render TOML nicely, given its author?) 🤖