Guilherme Raduenz

Moving away from GitBook to Hugo

I recently moved my website away from GitBook, and this is the first post on the new platform.

GitBook

The platform is great, and I will be using it for documentation projects.

My initial goal was to focus on content writing instead of coding a website from scratch, but I wanted to have control over the data (in a GitHub repository).

I wrote two articles there about stuff I was dealing with recently:

Problems

However, there was a simple problem on the platform that I never liked. When configuring a space, I have to choose a subdomain for it (gui.rdnz.dev) without being able to use the root domain (rdnz.dev).

My approach to this was to:

It worked very well, but I didn’t like it: it was a workaround, I just wanted it to literally bind the site to the root domain.

Also, there are some limits on the Cloudflare workers (100k requests/day) that contributed to the decision to get away from it.

Choosing a new platform

When choosing a new platform for the website, some requirements had to be met:

I know there are many options, but after some research my choice was Hugo.

I was able to build the whole website within a few hours, and its source code is also available on GitHub.

Extra: Cloudflare worker

In case you ever want to handle the problem with GitBook on Cloudflare like I did, here’s the code for the worker:

 1export default {
 2  async fetch(request, env, ctx) {
 3
 4    // Fetch from the gitbook website
 5    const url = new URL(request.url);
 6    url.hostname = 'gui.rdnz.dev'
 7    const res = await fetch(url);
 8
 9    const contentType = res.headers.get('Content-Type');
10    const isHtml = contentType && contentType.startsWith('text/html');
11
12    // If it's not HTML, just return the response
13    if (!isHtml)
14      return res;
15
16    // Otherwise, goes ahead with fixing meta tags for LinkedIn
17    var rewriter = new HTMLRewriter()
18      .on('meta', {
19        element(element) {
20          const name = element.getAttribute('name');
21          element.setAttribute('property', name);
22        }
23      });
24    
25    return rewriter.transform(res);
26  },
27};

#decisions

Reply to this post by email ↪