Skip to content

Instantly share code, notes, and snippets.

@nurrony
Last active July 10, 2020 15:39
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nurrony/77147308e38776031412 to your computer and use it in GitHub Desktop.
Save nurrony/77147308e38776031412 to your computer and use it in GitHub Desktop.
Auto git push script to post Ghost blog to Github Pages

Assumption

I am asumming that you have following this already taken care in your dev machine

  1. Fully configured up and running Ghost blog
  2. Successfully installed Buster Script
  3. Already have Git Page for your account

Instructions

Follow the steps below

  1. Go to your Ghost Blog root directory
cd /path/to/ghost/blog/root
  1. Clone your <your-username>.github.io repository in static directory under Ghost root directory. You can easily do it with the following command
git clone <your-repo-url> static
  1. Go to your ghost blog root directory if you are in static directory.
  2. Grab the ghost2git script running the following command and save it in your Ghost blog root directory
curl -fsOSL https://gist.githubusercontent.com/nmrony/77147308e38776031412/raw/ghost2git
  1. Open ghost2git in your favourite editor. Then find and replace the <your-github-username> with your github username. Save it.
  2. Make it executable using the following command
chmod +x ghost2git
  1. Run the script on your terminal using the following command when you add a blog post in your Ghost blog and want to push it to Gitpage
./ghost2git
# Read the configuration.md to configure this script according to your need
#!/bin/bash
CURR_DIR=$(pwd);
echo 'Generating static page from ghost blog..' && \
buster generate --domain=http://127.0.0.1:2368 > /dev/null 2>&1 && \
echo 'Fixing link...'
find ./static -name "*.html" -print0 | xargs -0 sed -i'' -e 's#http://localhost:2368#https://<github-username>.github.io#g' > /dev/null 2>&1 && \
cd ./static && \
echo "Pulling latest changes..." && \
git pull --all -q && \
echo "Adding changes to stage..."
git add --all && \
echo 'Enter git commit message: ' && read COMMIT_MESSAGE && \
git commit -am "$COMMIT_MESSAGE" && \
git push -qfu origin master > /dev/null 2>&1 && \
cd $CURR_DIR && echo 'Your blog is successfully deployed to github';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment