Stefano Cappellini

AI, Deep Learning, Machine Learning, Software Engineering

Why I chose Pelican over WordPress

Written on , in:

In the last year, I tried both WordPress and a static website generator (Pelican) and I finally decided to stick with Pelican. Let’s see why.

What is a static website generator?

Static website generators have gained a lot of attentions in the last few years, especially among geeks. Many engineers, data scientists and experts did the switch, removing their WordPress blog, increasing the hype around the topic.

But, what is a static website generator?

A static website generator is simply a tool that, as the name says, helps you building a static website (that is, a plain HTML websites, without any server side language used).

The workflow is the follow:

  • You firstly write your website’s content, ie your articles, your pages and so on. Each generator supports a specific set of formats and thus you can usually write your content directly as plain text files. For example, Pelican supports reStructuredText, Markdown and AsciiDoc formats.
  • Once you have your content ready, you can build your website, by using the generator (usually by calling it from the shell).

And that’s it. The generator does all the dirty work for you:

  • It converts the content you wrote to HTML and then it embeds each content into the appropriate templates files in order to obtain the final HTML files
  • It connects posts together, connecting them to their categories, it sorts all the posts by date,  it builds the archive pages and so on. In short, it builds and manages all the website structure and navigation, keeping that updated as you change your content.
The great difference from a WordPress website is that the building output is a plain HTML website. All this stuff is done at the building time and never again.

Pros of a static website generator

As I said, the website produced by a generator, is a static, full HTML website. This has lots of advantages.

Speed

The first is clearly the speed. The content is stored in plain HTML files that can be served as they are, without the need of being dynamically generated through PHP. The content is built once (during the building process, needed every time you change your content) and served many times. That also means that no MySQL query is required. In addition, a static web page can be easily cached, replicated and distributed using a CDN.

Security

Compared to a dinamically generated website based on a DB, a static website is obviously safer: you do not have to worry about sanitizing the queries, the injections and the content will not be interpreted by the web server: you could potentially disable PHP on your server.

In addition, compared to WordPress, you have no login pages, no third-parties plugins that could potentially contain bugs, no zero-days vulnerabilities in the core and so on.

You own the content

Your content is stored in plain text files and the entire website is written in HTML files. This means you can easily backup all your stuff, replicate it, store wherever you want in a matter of seconds. It is super easy to migrate your website too: you do not have to worry about the DB and the settings, you simply have to move some files.

Hosting free

Every web hosting support plain HTML files. This means you do not have to stick with a specific provider, you can change whenever you want. For example, a static website generator is perfect if you want to host your blog on Github.

Cons of a static website generator

Wow, a static website generator is truly great! Are they perfect? Obviously they aren’t! There are some cons too. Let’s see them

The building process

Yes, it is something you have to get used to. Every time you change something you have to build that content again. Now, in Pelican this is not as bad as it might sound:

  • When you are working on a single article or page you can use a specific option to build only that content (and the one related to it): --write-selected. Obviously it is not so easy. For example, if you are adding a new post, the generator has to change the previous post in order to incorporate a link to the newly added post.
  • You can automate this process, using Pelican itself or other building tools (I will write an article on this).

Even with these tips, this is a pretty cumbersome process that clearly makes Pelican (and, as far as I know, all the other static generators) not suitable for very big blogs or magazines. It is best suited for personal blogs. However, even for a personal blog, when the number of posts increases, this workflow does not scale so well.

The search

Personally, I love search boxes and I consider a search box a must have for every blog. A search box makes easy to find a particular post you saw on a blog when you do not have time to navigate around and it offers a perfect starting point for an interested reader. Yes, a search on Google can often help but it is not perfect. First of all, it is not (obviously) always up to date and, second, you have to add some filters in order to focus on a specific website, a slower process.

Pelican (and, as far as I know, every other static website generator) do not offer a built-in search functionality. This is pretty reasonable: being a static website, it is something hard to provide. If you look on Google, there are many ways to overcome this limitation:

  • Using Google Site Search: I personally do not like this solution. First of all, as I said before, the search is not always up-to-date and so the reader could easily miss the most recent content. Second, its layout will rarely fit yours well.
  • Using client-side JavaScript libraries like Tipue Search, Elasticlunr.js, Lunr.js, Fuse.js and so on, allowing the client to perform the search by itself. They basically work in the same way: you have to pass (synchronously or asynchronously) an object containing all the searchable contents to the client so that it can start its search. I do not like the idea of moving the computational load of the search to the client, I find it unfair. In addition, this solution does not scale well.
  • There are other solutions that performs the search on the server, such as Elasticsearch or Solr. However you have to set them up and find an hosting (if any) where they can be used.
  • There are also some commercial search services that I am not going to considered here: we are talking about a personal blog and they are absolutely not worth the fee.

WordPress (and its database) offers the search functionality (and many others) and a smoother process out of the box.

Conclusions: should you use a static website generator (aka what’s about Pelican vs WordPress)?

These are the conclusions I have come to:

  • Use a static website generator (like Pelican) if
    • You are building a static website (even a large one)
    • You are building a personal blog (small-medium size)
    • You do not need search or your blog is very small
    • You are willing to repeat the building many times
    • You love coding and getting your hands dirty
  • Use WordPress (or another CMS) if
    • You need dynamically generated contents
    • Your blog is (or is going to be) big, with lot of contents
    • Search is a key element for you and you have lot of contents
    • You are looking for a smoother process that allows you to focus only on your writing process
    • You do not like coding so much.

As regards myself

I love coding, getting my hands dirty, understanding how things work under the hood, hacking things, breaking and rebuilding them: I even built a LISP web server some years ago, just for fun. This is why I decided to stick with Pelican, even with the cons I described before. I love the sense of freedom it gives me. As regards the searching… I am working on it :)

comments powered by Disqus