For the “PostgreSQL Person of the Week” interviews I’m using Hugo as static blogging engine. Part of every interview is the list of tags, which links this interview to other similar interviews. However until recently no one really knew if a tag is popular or just used in this interview. I wanted to change this, and add the tag count behind every tag.
The way I use Hugo I have the previews also online, and I don’t want to count any interviews which are not published (still drafted) when counting entries for a tag.
Tags in Hugo are taxonomies, which is a user-defined grouping of content.
The original code in the overview page (themes/pglive/layouts/_default/single.html) looked like this:
| |
This loops over all tags in the current posting, and generates one link per entry.
In the new version I need to apply some filters before I can count the entries. First I need to exclude all pages which are still in review (drafted interviews), and second I only want posts, not news entries. Then I can count all interviews which include the current tag.
| |
Now every tag has a count after the name. Much more useful. See the result here. I added the same functionality in a couple other places, and also in the tag list overview.
What is Hugo
Hugo is a popular and open source static website generator. This blog is created using Hugo.
Development started around 2013, and the software is written in Go. The content of the website is written in Markdown, and then compiled into a website using the pre-defined layout. During development of new content, Hugo offers a life preview using the built-in server. It is very flexible, and offers a wide range of available themes and shortcuts.
Comments
With an account on the Fediverse or Mastodon, you can respond to this post. Known replies are displayed below:
Note: This will load data from mastodon.social.
Learn how this is implemented here.
Share: