All you need is pretty simple:

  1. A running Ghost (Can be Binary Installed or Docker, as long as you can open it via web);
  2. Download the entire static page;
  3. Create a new repo on Github and push the entire page on to it, then choose to enable github page and name it as “username.github.io”.

Key steps to make it possible

wget -r -m -nH -P docs -E -T 2 -np -k http://{{URL}}

This will download entire page and save into docs.

To make it even better

So now we have a static site on Github. But there’s a problem, every time when you change a thing in Ghost, you’ll need to git it and push onto github, and it’s quite painful and tedious. So let’s make it automatic.

  1. create a cron.sh file with following code:
cd /home/chz8494/blog
rm * -rf
curl http://localhost:8080
if [ $? != 0 ]; then
        python /home/chz8494/noc-slack.py
else
        wget -m -r -nH -E -T 2 -np -k http://localhost:8080
        for file in $(grep -lR '172.19.0.3' *); do $(sed -i s/172.19.0.4/chz8494.github.io/g "$file"); done
        for file in $(grep -lR 'localhost' *); do $(sed -i s/loca1host/chz8494.github.io/g "$file"); done
        for file in $(grep -lR 'http://chz8494' *); do $(sed -i 's/http\:\/\/chz8494/https\:\/\/chz8494/g' "$file"); done
        git add -A
        git commit -m "commit $(date)"
        git push origin
fi

So it not only update my site with github, but also has logic to detect if there’s trouble with my site, if there’s a problem, it’ll stop update and shoot out warnings to my Slack bot.

  1. crontab -e to make a cron job with */15 * * * * sh /home/$HOME/cron.sh, this will run every 15 mins.

Because my Ghost runs on docker-compose, so it got docker’s fake ip all over the place, and it gives trouble when pushed onto github, so I added 1 line to replace it. Now if you do any changes on Ghost, it will be updated to your Github site.