January 27, 2019
Every time I create new blog these are the steps involved. (until I realised easy way - see below for update)
As I was doing it manually, this is against DRY (Don’t Repeat Yourself) principle.
This is how I come up with automating this task with these bash scripts:
#!/bin/bash
REPO_DIR=/Users/vinkrish/Documents/workspace/javascript/vinkrish.github.io
cd $REPO_DIR
rm -r *
git add .
git commit -m "deleting cache and previous files"
git push origin master
#!/bin/bash
read blog_name
REPO_DIR=/Users/vinkrish/Documents/workspace/javascript/vinkrish.github.io
SRC_DIR=/Users/vinkrish/Documents/workspace/javascript/my-blog-starter
cp -R $SRC_DIR/public/* $REPO_DIR
cd $REPO_DIR
git add .
git commit -m "added $blog_name"
git push origin master
cd $SRC_DIR
git add .
git commit -m "added $blog_name"
git push origin master
You need to update .bash_profile
:
export PATH=$PATH:/Users/vinay/bin
Your script will be in bin directory:
cd ~
mkdir bin
Give permission for the script to be executable:
chmod u+x file_name
Now you can call file_name
from terminal.
Update: I realised gh-pages allowes public or docs folder of a app to be github pages, so I created another branch which has gatsby code and master branch now has generated public files, the above steps are unnecessary if you decide to go with this approach.