Skip to content

Instantly share code, notes, and snippets.

@Phlow
Last active Jan 23, 2018
Embed
What would you like to do?
Ask for a title and create a post for Jekyll in _posts and open in in your favorite editor
#!/bin/bash
#
# Create a post for Jekyll
# Configuration
EDITOR='Atom'
DATE=`date +%Y-%m-%d`
DOCFORMAT='md' # Without Point (!)
DIRECTORY='./_posts/'
# Get Input
clear
echo -e "\n"
read -p $'Title › ' TITLE
# Convert URL
TITLE_NO_HYPHENS=${TITLE// /-} # convert spaces in title to hyphens
TITLE_NO_HYPHENS_LOWERCASE=`echo "$TITLE_NO_HYPHENS" | tr '[:upper:]' '[:lower:]'` # convert title to lowercase
PERMALINK=${DATE}-${TITLE_NO_HYPHENS_LOWERCASE}.${DOCFORMAT}
FILE=$DIRECTORY/$PERMALINK
# Show content
echo -e "\n---
title : $TITLE
permalink : /$TITLE_NO_HYPHENS_LOWERCASE/
# meta_description :
---"
echo -e "\nCreate $PERMALINK in $DIRECTORY?\n"
select yn in "Yes" "No"; do
case $yn in
Yes ) break;;
No ) echo "\nAbort mission";exit;;
esac
done
# Create file
touch $FILE
# Write content into new posting
echo "---
title : $TITLE
permalink : /$TITLE_NO_HYPHENS_LOWERCASE/
# meta_description :
---" > $FILE
open $FILE -a "$EDITOR"
@oe7drt

This comment has been minimized.

Copy link

@oe7drt oe7drt commented Jul 27, 2017

You forgot that you declared a variable to use any editor. 😃

open $FILE -a "$EDITOR"
@Phlow

This comment has been minimized.

Copy link
Owner Author

@Phlow Phlow commented Jan 23, 2018

@freefallcid Thank you for your comment. Just saw it today. Got no notification. Stumbled across it by chance and edited the gist. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment