Greg Morris

Follow @gr36 on Micro.blog.

How To Filter Posts By Category On Micro.blog

I’ve been using the awesome service micro.blog on and off for what feels like forever. The service is niche, and a bit quirky, but that’s my thing, and it is the perfect replacement for noisy social media. Don’t get me wrong, it’s far from perfect, but allows me to not have to worry about where I post things and cross posts to wherever I want. Enough of the gushing now, what really annoyed me for a while was working out Hugo theming and the little nuanced micro.blog differences, and I have finally worked out how to split posts by category properly.

Micro vs Full Posts

I have a constant argument with myself if this matters or not, and ultimately, it doesn’t, but I have always felt that my Home Screen is too busy with everything mixed into one place. I’ve been able to remove all micro posts for a while, but decided to come up with a way to display micro ones separately. The key to my new set-up is creating different lists in the Hugo back end.

Most themes will feature something similar to {{ $paginator := .Paginate (where .Site.Pages.ByDate.Reverse "Type" "post") }} in the layouts/index.html. What this means is that Hugo will paginate all the posts on the blog. Your theme will then go through all of these pages when you use {{ range $paginator.Pages }}.

My old solution was to put different data into the paginator, such as .Site.Taxonomies.categories.[yourcategory] and this works fine. However, we can make this more robust by creating different pools of data to use at different points. By using {{ $microposts := .Site.Taxonomies.categories.micro }} I am telling Hugo to pull all posts in the category micro into a list called microposts alongside the usual $paginator. This can be anything you want by using the same method {{ $[list name] := [the data to find] }}. all categories in micro.blog are found using Site.Taxonomies.categories not the usual Hugo of Params.categories.

I can then call this data later on and cycle through the posts at a different point using {{ range $[list name] }}. In my new theme, I now have a main area that displays full posts (those with a title) and micro posts (those without a title) in a sidebar. I’ve also added in my OMG.LOL status widget too, if you want to customise that, take a look at my guide.

I am by no means an expert, and I am certain this knowledge is well known, but I thought I would share it so that others can benefit from it.

Comments

via webmention
✴️ Also on Micro.blog