Created
February 1, 2019 03:30
-
-
Save dceddia/0283d88549d610e3edb9f5f24a118f62 to your computer and use it in GitHub Desktop.
Create a new post based in Gatsby. (make sure to create a new-post-template.md file)
This file contains hidden or 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 | |
# Print usage if args are missing | |
if [ -z $1 ]; then | |
echo "Usage: new-post <slug>" | |
exit | |
fi | |
SLUG=$1 | |
DAY=$(date +%Y-%m-%d) | |
DATE=$(date +%Y-%m-%dT%H:%M:%S%z) | |
FILE=content/blog/$DAY-$1.md | |
# Don't overwrite existing posts | |
if [ -f $FILE ]; then | |
echo "That post already exists." | |
exit | |
fi | |
# Copy the template into place, replacing | |
# the TITLE and DATE | |
cat new-post-template.md | sed -e "s/TITLE/$SLUG/g" | sed -e "s/SLUG/$SLUG/g" | sed -e "s/DATE/$DATE/g" > $FILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment