Created
November 1, 2021 01:39
-
-
Save slayerlab/2edb0d212bd2af3abe3f2329908dcf81 to your computer and use it in GitHub Desktop.
This script helps to create a new Jekyll post quickly.
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 | |
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