===============
== bacardi55 ==
===============
ἕν οἶδα ὅτι οὐδὲν οἶδα

Add a list of related posts per tags with hugo

- Permalink
/!\ Warning: This article is older than 555 days, make sure the content is still relevant!

Similar to my previous post about alerting on old post, this is a simple reminder for my future self. To add related posts per article on hugo, first, configure the related search configuration:

[related]
  includeNewer = true # to include newer result that current post
  threshold = 80
  toLower = true # to compare lower case content

And the configuration for the tag index:

[[related.indices]]
    applyFilter = false
    cardinalityThreshold = 0
    name = 'tags'
    pattern = ''
    toLower = true
    type = 'basic'
    weight = 80

Then, I added a new partial in my single.html theme file (MinIndie theme):

{{ if .Site.Params.enableRelatedPages }}
    {{ partial "article-related.html" . }}
{{ end }}

And added as default in article-related.html partial:

{{ $related := .Site.RegularPages.Related . | first 5 }}
{{ with $related }}
    <h2>Releated Posts</h2>
    <ul>
        {{ range . }}
            <li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
        {{ end }}
    </ul>
{{ end }}

Then, in config.toml, to enable related articles:

[params]
  []
  enableRelatedPages = true

And voilà, there is now a list of up to 5 related articles at the bottom of each article now :).


Contact

If you find any issue or have any question about this article, feel free to reach out to me via webmentions, email, mastodon, matrix or even IRC, see the About page for details.