Skip to content

Instantly share code, notes, and snippets.

@dceddia dceddia/new-post.sh
Created Feb 1, 2019

Embed
What would you like to do?
Create a new post based in Gatsby. (make sure to create a new-post-template.md file)
#!/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
You can’t perform that action at this time.