Last active
August 29, 2015 14:00
-
-
Save harlo/11216974 to your computer and use it in GitHub Desktop.
automatic jekyll posts!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
BLOG_DIR=/where/is/your/jekyll/blog | |
ASSETS_DIR=$BLOG_DIR/subpath/for/your/assets/like/images/or/whatever | |
function join { local IFS="$1"; shift; echo "$*"; } | |
MAKE_TITULAR_DIR=false | |
if [ $# -eq 0 ] | |
then | |
TITLE="new_post" | |
TITLE_STUB=$TITLE | |
else | |
TITLE=$1 | |
TITLE_STUB=$(echo $(join - $TITLE) | tr '[:upper:]' '[:lower:]') | |
echo $TITLE_STUB | |
MAKE_TITULAR_DIR=true | |
fi | |
YMD=`date +%Y-%m-%d` | |
declare -a DATE_ARRAY=(`date +%Y` `date +%m` `date +%d`) | |
PAR_DIR=$ASSETS_DIR | |
cd $PAR_DIR | |
for DIR in "${DATE_ARRAY[@]}"; do | |
echo "finding $DIR in $PAR_DIR" | |
has_dir=`find $PAR_DIR -type d -name "$DIR"` | |
if [[ -z "$has_dir" ]]; then | |
echo "making new directory $DIR" | |
mkdir $DIR | |
fi | |
PAR_DIR=`pwd` | |
cd $DIR | |
done | |
if $MAKE_TITULAR_DIR; then | |
mkdir $TITLE_STUB | |
fi | |
cat << EOF > $BLOG_DIR/_posts/$YMD-$TITLE_STUB.markdown | |
--- | |
layout: post | |
title: "$TITLE" | |
date: `date +%Y-%m-%d` `date +%T` | |
--- | |
EOF | |
# CHANGE THIS TO WHATEVER COMMAND OPENS UP STUFF IN YOUR TEXT EDITOR OF CHOICE :) | |
open -a /Applications/TextWrangler.app $BLOG_DIR |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment