Ein Baum und seine Abenteuer



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.
gulp.task('html', function () {
  gulp
    .src('./public/**/*.html')
    .pipe(minifyInline())
    .pipe(htmlmin({ collapseWhitespace: true }))
    .pipe(gulp.dest('./public'))
})

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).

Chinas great wall didn't cause me trouble but the great firewall did.
Chinas great wall didn't cause me trouble but the great firewall did.

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).

New workflow

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.
script:
- npm install -g gulp
- npm install
- gulp hexo
- gulp

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.

Author

Portrait picture of Hendrik

I am a JavaScript and GenAI Enthusiast; developer for the fun of it!
Here I write about webdev, technology, personal thoughts and anything I finds interesting.

More about me

Read next

Deploy a hexo blog from Github using Travis

Read on 😉
Read on 😉

Straightening a lot of things out at the moment I got stuck with my blog.

This should be about the fourth blog I have run in my life. And so far the longest standing one. Mainly thanks to my stay in China. And it has gone through multiple stops so far.

First it was a wordpress powered blog hosted on my webspace at der-grüne-baum.net. That rapidly turned into a maintenance nightmare of "Wordpress needs a security update". So in September of 2015 I took a look around for alternatives and found Hexo. A Node based static blog generator. Technology wise totally my thing and static means pure HTML files without so much security stuff going on. So I switched to Hexo at first uploading by hand via FTP. Last year while I stayed in China the manual upload didn't work so great anymore. The connection just didn't take it. So I moved my blog to GitLab. They had native support for Hexo based sites. I never managed to get the domain moved to there however. So now in 2017 I set out to go for the new domain hoverbaum.net and have it there.

Ein Baum in China: Vorbereitung

Es folgt ein längerer Beitrag darüber, wie ich mich in den letzten 17 Monaten mehr oder weniger geplant auf meine Reise nach China vorbereitet habe.

Holiday greetings with GenAI

Festive Greetings - ChatGPT and Midjourney
Festive Greetings - ChatGPT and Midjourney

Happy Holidays and festive greetings, powered by ChatGPT, Midjourney and a little bit of Photoshop.

Utilizing my Custom GPT for Midjourney prompts (open source on GitHub), I generated the image and some subtle variations in three rounds. Finally touching it up with a tagline in Photopea.