Tools for working with Frontmatter

Scripts

Convert Hugo directory from YAML <–> TOML

hugo convert toYAML --output content_as_yaml

Shell script to prepend frontmatter from template

This script finds markdown files, then prepends YAML front matter following the template from prepend.sh.

## For each result of find call our script to run on the filename
$ find . -name "*.md" -print0 | xargs -0 -I file ./prepend.sh file
## Given a file path as an argument

## 1. get the file name

## 2. prepend template string to the top of the source file

## 3. resave original source file

filepath="$1"
file_name=$(basename $filepath)

## Getting the file name (title)

md='.md'
title=${file_name%$md}

## Prepend front-matter to files

TEMPLATE="---
layout: page
title: $title
category: gen
---

"
echo "$TEMPLATE" | cat - "$filepath" > temp && mv temp "$filepath"

Related