Skip to content

Instantly share code, notes, and snippets.

@jacobwyke
Created February 7, 2018 07:41
Show Gist options
  • Save jacobwyke/3b99fa6175982e08603df2ae74a352cd to your computer and use it in GitHub Desktop.
Save jacobwyke/3b99fa6175982e08603df2ae74a352cd to your computer and use it in GitHub Desktop.
Bash script to add a new Jekyll post with the correct file name and front matter
#!/bin/bash
strBaseFolder=`pwd`/
strDate=`date +"%Y-%m-%d"`
strTime=`date +"%H:%M:%S %z"`
if [ "$#" == 0 ] || [ "$#" -gt 1 ] ; then
echo "Usage: $0 'post title'"
exit;
fi
strTitle=$1
strCleanTitle=`echo $strTitle | sed -e 's/ /-/g' | tr '[:upper:]' '[:lower:]'`
strFilename="$strBaseFolder$strDate-$strCleanTitle.md"
#write the new post file
read -d '' content <<EOL
---
layout: post
title: $strTitle
date: $strDate $strTime
---
EOL
echo "$content" >> $strFilename
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment