Skip to content

Instantly share code, notes, and snippets.

@ckunte
Last active June 30, 2018 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ckunte/4d16ad5f0a2dfa09327e186baf7deea5 to your computer and use it in GitHub Desktop.
Save ckunte/4d16ad5f0a2dfa09327e186baf7deea5 to your computer and use it in GitHub Desktop.
A number of static site generators use front matter. This script would be handy to update the front matter labels. Run this from within posts folder to prepend first and second lines with `title =` and `date =` respectively.
for f in *;
do sed '1i\
title: ' < $f > tmp_$f ;
mv tmp_$f $f ;
done
for f in *;
do sed '2i\
date: ' < $f > tmp_$f ;
mv tmp_$f $f ;
done
for f in *;
do sed '3i\
tags: ' < $f > tmp_$f ;
mv tmp_$f $f ;
done
for f in *;
do sed '3G' < $f > tmp_$f ;
mv tmp_$f $f ;
done
for f in *;
do echo "---\n$(cat $f)" > $f;
done
for f in *;
do sed '4G' < $f > tmp_$f ;
mv tmp_$f $f ;
done
for f in *;
do sed '5i\
---' < $f > tmp_$f ;
mv tmp_$f $f ;
done
# Update date line
for f in *;
do sed -E 's,([0-9]{2})/([0-9]{2})/([0-9]{4}),\3-\1-\2,g' < $f > tmp_$f ;
mv tmp_$f $f ;
done
# Append timestap to date line
for f in *;
do sed '3s/$/T21:00:00+05:30/' < $f > tmp_$f ;
mv tmp_$f $f ;
done

Add frontmatter to posts written for Chisel to be compatible with Jekyll or Hugo

Two scripts to run one after the other in the order shown:

cd posts
sh ../fm1.sh
sh ../fm2.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment