Skip to content

Instantly share code, notes, and snippets.

@slayerlab
Created November 1, 2021 01:39
Show Gist options
  • Save slayerlab/2edb0d212bd2af3abe3f2329908dcf81 to your computer and use it in GitHub Desktop.
Save slayerlab/2edb0d212bd2af3abe3f2329908dcf81 to your computer and use it in GitHub Desktop.
This script helps to create a new Jekyll post quickly.
#!/bin/bash
JEKYLL_PATH="YOUR_JEKYLL_PATH"
POST_DATE=$(date +%Y-%m-%d)
TITLE=$1
FILENAME="$POST_DATE-${TITLE//\ /-}" || ""
[[ -z "$TITLE" ]] \
&& {
echo >&2 "[!] Filename not set." \
&& exit 1;
}
[[ ! -f "$JEKYLL_PATH/$FILENAME" ]] \
&& (
POST_NAME=$JEKYLL_PATH/$FILENAME \
&& echo "---" > $POST_NAME \
&& echo "layout: post" >> $POST_NAME \
&& echo "title: $TITLE" >> $POST_NAME \
&& echo "---" >> $POST_NAME \
&& echo -ne "\n\n" >> $POST_NAME \
&& vi "+normal G $" +startinsert $POST_NAME
) || {
echo >&2 "[!] The file $FILENAME already exists." \
&& exit 1;
}
# EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment