Jan-Lukas Else

Thoughts of an IT expert

How I automatically create my blogroll

Published on in 👨‍💻 Dev
Updated on
Short link: https://b.jlel.se/s/f
⚠️ This entry is already over one year old. It may no longer be up to date. Opinions may have changed. When I wrote this post, I was only 20 years old!

I just updated my blogroll and thought that it might be a great idea to share my workflow to do exactly that.

I use Miniflux a lot. Using Miniflux, I read all the blogs and get all the news, get updates from all the YouTubers and even subscribe to some Mastodon accounts (fediverse microblogs). I use multiple categories to sort the feeds. One of those categories is “Blogs” with all the blogs, which I also list on my blogroll.

The list of blogs I follow is always evolving. Sometimes I find new sites to follow, so I add their feeds to the list of subscriptions and put them into the “Blogs” category. Sometimes I also unsubscribe from feeds when they are inactive or if I’m not that much interested into them anymore (it can have multiple reasons).

To keep my blogroll up-to-date and to avoid having to manually compare and adjust the list with the list from Miniflux when updating it, it is automatically created using a Hugo shortcode.

First, I create an OPML export from my Miniflux subscriptions. This can be easily done by going to “Subscriptions” and then clicking on “Export”. I open the download with a text editor and remove all the categories that aren’t “Blogs”. I copy the remaining OPML code and convert it to JSON using this tool. This JSON I store in a file named opml.json in the data folder of my Hugo-based blog.

In the layouts/shortcodes folder, I created a shortcode template named blogroll.html with the following content:

<ul>
    {{ $opmlJson := index .Site.Data.opml "opml" "body" "outline" "outline" }}
    {{ range sort $opmlJson "_title" "asc" }}
    <li><a href="{{ ._htmlUrl }}" target="_blank">{{ ._title }}</a></li>
    {{ end }}
</ul>

This shortcode is then used by adding {{</* blogroll */>}} in the blogroll content file.

In the end, all I have to do to update my blogroll is update the opml.json file and update the lastmod frontmatter parameter in the blogroll content file.

Check out my blogroll!


Update: Robert van Bregt asked, why I’m not just uploading my OPML file and then filter and render the blog category at runtime. Unfortunately, Hugo doesn’t support XML (yet) and OPML is basically XML. That’s one reason. Another reason is, that I don’t want my whole OPML file to be version controlled (I use Git for my blog).


Update 2: Check out how I automated the whole thing.

Tags: ,

Jan-Lukas Else
Interactions & Comments