An annoying bug in the Hugo tranquilpeak theme
I started this blog last September, and I haven’t used it until this January. I began to write some articles this April regularly, so I was not entirely familiar with blogging, and it seems that no so many people know and visit this blog. Earlier today, when I tried to click on the tags under the article, I found that there is a bug corresponding it that it uses two backslashes instead of one. As a result, it became absolute reference instead of relative reference and caused 404 Error.
After I figured that out, I thought this problem must happen in the theme, not the Hugo builder. I started to check the corresponding codes, but not yet identified the problem. I tried to access the code base online at GitHub, but I cannot locate the exact location of the code chunk. So what should I do?
I took a look at the structure of the theme at the Hugo website, and I found that the layout folder contains all of the HTML files that are used to render the post. I then went to the “/partials/post” subdirectory and saw tag.html. I opened it and compared it to the similar category.html, and I found the difference. Let me show the code here so that you could see the actual difference.
1 |
{{ range .Params.tags }} <a class="tag tag--primary tag--small" href="{{ $.Site.LanguagePrefix }}/tags/{{ . | urlize }}/">{{ . }}</a> {{ end }} |
1 |
{{ with .Params.categories }} {{ $categoriesLen := len . }} {{ if gt $categoriesLen 0 }} <span>{{ i18n "post.categorized_in" }}</span> {{ range $k, $v := . }} <a class="category-link" href="/categories/{{ . | urlize | lower }}">{{ . }}</a>{{ if lt $k (sub $categoriesLen 1) }}, {{ end }} {{ end }} {{ end }} {{ end }} |
You could now see the difference: the href in the category.html don’t have the leading part {{ $.Site.BaseURL }}, and it works fine. I suspect that there are some errors in loading the BaseURL, so it uses the default backslash. There are two backslashes together after combining with the backslash after and causing the problem. After deleting that part, the tag feature works like a charm!
In the end, I want to say that there are still lots of works to be done to modify the blog theme, especially in a not-so-popular blog theme, and it is inevitable to have some bugs in that process. Keep trying, and you will improve your skills and have a better blog!