Blog Switched to Hugo

In less than half a year, I have revamped my blog again. I spent more than two days switching the blog from the original Hexo + Stun to Hugo + MemE. There are many reasons for wanting to switch, for example:

  • The speed at which Hexo generates pages has become a bit slow. I have only about 70 pages, and each build deployment plus submission may take one to two minutes, and as the content written over time increases, it will take longer and longer.
  • The original theme seemed a bit inappropriate. Now I prefer the blog style to be simpler, allowing the focus of the website to return to the text itself. This also prompted me to ban all non-centered article bodies when choosing a theme this time.
  • The original blog feels like there are too many useless and verbose pages and features, including the so-called background music playback. In order to have a better background music playback experience, I had to use PJAX. But in fact, I have only clicked to play the background music a few times.

Of course, the main reason for wanting to change is that I like to toss around. In the past two days when I was messing with the blog, I felt the long-lost state of concentrating all my thoughts on one thing. When migrating the blog, choosing a theme, configuring the environment, writing migration scripts, rewriting the theme to get the desired effects and functions, although I encountered some pits, I still had continuous motivation to continue and improve. It seems that I really like to mess with things from my heart.

Migration Preparation

Since there are some differences between Hugo and Hexo, and the theme I chose is different from the original theme, some changes need to be made when migrating the blog to Hugo to achieve a seamless transition.
The main issues to consider are:

  • Path organization differences
  • Category tag differences
  • Comment function implementation

Path

In Hexo, the path of the article is configured by the permalink in the root directory configuration file, which can use common basic variables (year, month, title), or variables defined in the front matter.

Hugo, on the other hand, builds page links based on the organization of files in the content directory by default. You can also achieve this by configuring the permalink attribute under the configuration file, but the variables you can choose are relatively few, usually year, month, day, title, and filename, and do not support the use of custom front matter variables.

The style of my previous blog links was all /:year/:urlname, and I defined the path of the article in the front matter. At first, I couldn't find the correct configuration of the permalink. In the end, I used the url attribute in the front matter to forcibly determine the link of the article. So I wrote a script to change all the urlname attributes in the Markdown files to url, and added the year before the value, hardcoding it into the form of /:year/:urlname. Later I found that the slug variable could pass values to the permalink, so I set posts = "/:year/:slug/" in the configuration and then wrote a script to convert the url attribute to slug and remove the year encoding in front.

Category Tags

When I first copied a few articles to Hugo, I always found that the operation failed, indicating that the range cannot iterate over a certain category or tag. If I delete them, it can run correctly. Later I found out that the theme MemE I was using always presumes these properties to be in array form, so if the category or tag is written in the single-line form tags: val, it will go wrong. It needs to be written in multiline form:

1
2
tags:
- val

Why does the category (category), which clearly only has one, need to use an array? Here Hugo is a bit different from Hexo. Hugo's categories are somewhat similar to tags. What is more like Hexo's categories in Hugo is sections, which are organized by the file structure of the directory.

Considering this difference, I simply deleted all the categories through the script. The classification of articles is organized through tags.

Comment Function Implementation

I previously used the Waline comment system. The chosen theme only provides Valine settings, and the implementation is incomplete and unusable. So I followed its logic and wrote a Waline implementation, implemented the unimplemented parts, and added the display of article reading volume.

What Does a Blog Really Need?

When migrating a blog, you need to reconsider the functionality and content of the blog. This made me rethink this question: When writing a blog, what do I need, and what do I need to show to others?

In the beginning, writing a blog was nothing more than taking technical notes, most of the time copying and recording, with few of my own ideas. And such technical articles are not easy to create, which leads to infrequent updates and insufficient content. So, it's easy to focus on the blog itself, not the content of the article, always thinking about adding some features to the blog, how to make the blog look better, and attracting people to the blog in this way. So it's getting more and more fancy, and it's getting slower and slower to open. Such a blog may indeed give people a bright feeling when they open it, but only the first time.

When I was looking for a blog theme for my girlfriend in the previous letter, I chose a great minimalist style theme. This theme made me realize that I should return to the content of the blog itself and refocus people's eyes on the text. So this time when selecting a Hugo theme, I adhered to this condition, one is to be simple, and the other is to focus on text. The current theme feels like it can meet my requirements very well.

But when I write here, I feel that in the creation of blog content, it seems that I have also fallen into a bottleneck position. Writing technical articles, simple document-like ones are time-consuming and cumbersome, it's better to read the official documents. More complex and technical articles will increase the reading threshold; recording my own pit experience and reflections, but if there is no similar specific scenario, it sometimes tastes a bit tasteless. Writing life articles, I, who is busy with schoolwork and trapped in campus, seem to not find more time to really live. Even if I encounter interesting things, the first thing I will think of is to record them in private weekly records. As for content in various areas such as practicing boxing, health preservation, reading, etc., I feel a bit half-hearted.

But the question is: Can't you write if the article is not good enough? Obviously not, the less good it is, the more you have to write. Only through more writing and practice can we promote the improvement of the level, including the writing level and the field level involved in the written content.

As written in my updated personal introduction

🎨 A jack of all trades but not enough mastery

I hope I can become a versatile person from a jack of all trades soon!