Running a blog in China
Reader of my adventures in China beware! This post is in English and will get technical. You have been warned.
Turns out running a blog in China is not the easiest thing. Well actually running a blog in itself is quite some work but that is a different topic.
My blogs history
After moving through several “blogging providers”, you know trying out Tumblr and Blogger and others. I never really kept a blog. But then I wanted to make a site for multiple little projects that I was doing at the time and decided to put them all together with a little blog. That seemed like enough content to keep it going. As I said running a blog is work and hard. And I like to not work. But back to story time: So I set up a wordpress blog. And what did that get me? An email about every other week telling me to update some security flaw in the System. With me releasing posts only once a month or so at best that was a sorry state. So I switched to Hexo.
While Wordpress dynamically generates pages from information in a database Hexo takes in Markdown files and generates static HTML. The advantage being that static HTML files do not have security risks with them as they do not expose any database or similar thing.
Working with Hexo
Being a webdev I wanted to make the generated files better. So obviously they should go through some automated post-processing which should also upload them via FTP to my server and all that with one command. Easy enough. Just get a few gulp tasks running and a simple
gulp all would get the new version online. Very nice.
//Minify the generated HTML.
You can have a look at the entire gulpfile I use in this gist.
Moving to China
Since coming to China however I have been facing multiple issues with this approach. One is that static file generation and optimization afterwards make sure that absolutely all files change. And all changed files need to be uploaded. So not only does every blog post and every index page have to be uploaded (as they are all just static html) but also every image. That can get to a lot of things to upload quite quickly. Or at least if you are sitting in a dorm with not enough Internet for way to many students.
And then of cause connecting all the way to Germany with sometimes having a firewall in the mix doesn’t help either. In fact I even got tons of disconnects while the FTP upload was working when I tried it at work. And work has better Internet (that HongKong Internet).
So while the questions of many people back home as to why a certain post was not there certainly made me happy about how many people are actually reading my blog. It also made the situation annoy me that much more.
GitLab to the rescue
There is an obvious solution to part of my problem. While I can’t really solve the fact all file change and my readers browsers will think they need to download the header again every time I make a new post. I can at least make the upload and my life easier. Using git. Because that works perfectly and is never blocked. For a few weeks actually I was toying with the idea to set up a script on my server that would pull the up-to-date version from a git and compile it. That way I would only need to upload to a git and the rest would be on a remote server, not a problem.
But that would have been some work involved and I would need a server.
Lucky me though, GitLab announce GitLab Pages which is basically the same thing as GitHubs pages. With the difference that they support Hexo while GitHub only supports Jekll (or however that Ruby gem is spelled).
So now I still write my blog the same as before and run a
hexo serve locally to check the result. But after that I simply make a commit and GitLab runns a task on their server to generate the blog. I had to use my username subdomain for this because else Hexo had some trouble with finding its resources (which I am sure one could fix given an hour). But that way all I had to do was point my domain to a different IP and set up my project on GitLab to use it.
//Now GitLabs CI runs the scripts for me on their server.
GitLab has an article on how to get started using their pages as well as a demo Hexo project. I still use the same gulpfile as before only that now GitLabs CI is running it for me. Have a gist with all the config files.
Super simple to set up and run, work like a charme even from China.⬅️ Go back