Skip to content

Instantly share code, notes, and snippets.

@Phlow
Last active January 23, 2018 12:17
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 Phlow/59625dc4afd85560ed667f8423958b64 to your computer and use it in GitHub Desktop.
Save Phlow/59625dc4afd85560ed667f8423958b64 to your computer and use it in GitHub Desktop.
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
Copy link

oe7drt commented Jul 27, 2017

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

open $FILE -a "$EDITOR"

@Phlow
Copy link
Author

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