Wordpress sites are really great for customizing and making our site beautifull. No matter what other platform rise, wordpress always seems to take advantage of itself being easier to both customizing and hosting. However if our website were static, then we don’t have to even spend dime on hosting because as a developer we have one great solution here GITHUB.

Github is one of the most easiest site to host our static HTML/Jekyll sites. But this doesn’t mean we can’t use it for wordpress. In fact, we can use the github to host our static wordpress site. For this we need our site to be converted to HTML. In case of wordpress, the best solution is to use the plugin such as Simply Static. Once your converted site is downloaded in local storage, you can use normal method to deploy your website in github.

But what if your site being static was updated once in fortnight or as per your wish?

Well just for this purpose, i wrote the following script to make the task easier.

(Requirements: For this script, it was assumed that the working directory was github repo)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/bash
#Script to auto deploy the generated Static WP site to Github
#Check if unzip is installed or not

if apt-cache policy unzip >/dev/null 2>&1; then
echo "Unzip is installed. Moving onto next step."
else
echo "Unzip wasn't detected. Installing Unzip... Please wait."
sudo apt-get --force-yes --yes install unzip
fi

#making dir and unzipping the content
mkdir wptmp
unzip wps.zip -d ~/wptmp

#making tmp directory for moving .git folder
mkdir gittmp
mv ~/wordpress/.git ~/gittmp
cp ~/wptmp/deploy-wp-static-github.sh ~/wordpress
mv ~/gittmp/.git ~/wordpress/
cd wordpress

#git commands
{
git add .
git commit -a -m "$1"
git push
}

#removing temp directory
rm -rf ~/wptmp
rm -rf ~/gittmp

As i am ubuntu user, this is intended for all ubuntu user. I hope to extend for other distros in near future. You can use other unzipping services by replacing unzip to your favorite app. You can also find more like this and other bash snippets and scripts.