11 Jul 2020
I’ve recently transitioned from writing on WordPress to a self-hosted solution using GitHub pages, which in turn uses Jekyll for static content generation, which in turn uses Liquid for markdown processing.
There were about a hundred posts and my old blog and I wanted to bring them all into my new site to keep everything in one place although I’m keeping the wordpress blog for historical purposes).
In this meta post we’ll describe some of the steps taken to convert WordPress posts into a mark down one and changes I needed to make to support features from WordPress.
I used Python for the processing.
Wordpress offers a way to download all the posts and their metadata as XML which is very convenient. Python on its turn has
One difficulty I had was matching tags with namespaces such as:
Won’t do, you need to provide an additional parameter, the namespaces. They’re listed in the XML itself, in my case:
And can be retrieved as
Finally we can search by
To facilitate the translation between wordpress HTML-ish (it also includes non-HTML tags such as
[caption], etc) and markdown I wrote a parser to generate an intermediate AST and then a markdown generator to convert the AST to markdown.
The hardest case was converting images with caption, since it had several cases some of which required re-structuring the AST.
The ast was:
There was also
And finally plain images
I opted to wrap them all into <figure> for consistency and to have less output formats.
Liquid has good integration with MathJax. The only change needed is to include
This post was very helpful.
I started using Gists in wordpress because the
[sourcecode][/sourcecode] code from wordpress was subpar. Gists have their own set of issues, like the extra frame and sometimes failing to load on mobile. Liquid has nice support for code highlighting, so I just needed to download the contents.
Github has a REST API to download Gists but the rate limit is very low (1 gist/min) if logged out, while logged in it’s ~100x higher. The github official documentation was not very friendly on explaining how to programmatically authenticate with your own user, but this post was very helpful.
We can then use the requests Python library to get the data:
I wanted to change my blog to use HTTPS, since Chrome now shows a “not secure” warning on HTTP-only sites.
Github supports HTTPS on its pages but if you have custom domain it doesn’t work out of the box.
I have a custom domain, kuniga.me, which I register using DreamHost. I don’t fully grasp the intricacies of CNAME and A records, but this post made it work.
I opted to use Facebook’s comment plugin to allow social interaction with my posts. The reason is that most people have a Facebook account and it handles spam / bots. I might have been partial on that choice ;)
The integration is very easy. It associates the posts to a given URL, so I added the following Liquid snippet at the end of a post template:
The only downside was to lose all the comments from previous posts.
I opted to use Google Analytics funcionality. I just embed some script on top of every page template and it automatically gathers data which is helpful to determine the most popular posts.