Skip to content

Instantly share code, notes, and snippets.

@JKirchartz
Last active December 18, 2015 06:59
Show Gist options
  • Save JKirchartz/5743544 to your computer and use it in GitHub Desktop.
Save JKirchartz/5743544 to your computer and use it in GitHub Desktop.
Scripts to create a new post & publish it using jekyll. `new_post` takes a title, and optional content; `publish` stages it for publishing on the current date.

Scripts to create a new post & publish it using jekyll. new_post takes a title, and optional content; publish stages it for publishing on the current date.

new_post "Article Title" "Optional content" will create a file named unpublished-article_title.md whose content is

---
layout: post
title: Article Title
published: false
tags: article
---

Optional content

publish unpublished-article_title.md

will rename the file to the current date, and remove the unpublished flag

so if today is June 9th 2013 the file is renamed 2013-06-09-article_title.md

#!/bin/bash
# create a new jekyll post
# by supplying a title
# and optional content
if [ -z "$1" ]
then
read -p "Post Title:" TITLE
else
TITLE="$1"
fi
FILE=$( echo $TITLE | tr A-Z a-z | tr -d '[:punct:]' | tr ' ' _ )
FILENAME='unpublished-'"$FILE"'.md'
echo -e '---\nlayout: post\ntitle: '$TITLE'\npublished: false\ntags: article\n---\n' > $FILENAME
if [ -n "$2" ]
then
echo "$2" >> $FILENAME
fi
#!/bin/bash
# publish jekyll post made with new_post.sh
if [ -z "$1" ]
then
read -p "Post filename:" FILENAME
else
FILENAME="$1"
fi
if [ -f "$FILENAME" ]
then
NEWFILE=$(echo $(date +%Y-%m-%d)$(echo $FILENAME | cut -c12-1000))
sed -e 4d $FILENAME > $NEWFILE
rm -f $FILENAME
else
echo "not a filename"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment