Skip to content

Instantly share code, notes, and snippets.

@dceddia
Created February 1, 2019 03:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dceddia/0283d88549d610e3edb9f5f24a118f62 to your computer and use it in GitHub Desktop.
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)
#!/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