talkgroup

A script to add front matter to pages

Tags: #<Tag:0x00007f736bae47b0> #<Tag:0x00007f736bae4670>
#!/bin/bash

front_matter="toc: false"
dir="content/post"
pages="$(find $dir -name "*.md")"
tmp="tmp.md"

for page in $pages; do 
  awk -v front_matter="$front_matter" '/---/{
    c++;
    if (c==2) {
      sub("---",front_matter "\n---")
    }
  } 1' $page > $tmp
  mv $tmp $page
done
1 Like