Using Hugos Related Content feature

I’m looking at implementing a “Related Posts” feature in the Cards Theme.

I see that Hugo has a “Related Content” feature, but I think it relies on keywords, tags, or other metadata provided in the markdown YAML. I don’t know if Micro.blog uses these.

My understanding is that Micro.blog uses Categories, which may be different than Tags. Therefore, the Related Content feature in Hugo, would not be useful.

I am able to get the “Related” posts based on the category, but it is not very smart. It is only showing the top X posts in the same category as the current post.

Any other suggestions? Has anyone else experimented with this feature?

{{- range first 1 (where (where .Site.Pages ".Params.categories" "intersect" .Params.categories) "Permalink"
"!=" .Permalink) -}}
{{- $.Scratch.Set "has_related" true -}}
{{- end -}}

{{ if $.Scratch.Get "has_related" }}
<div class="related-content">
    <strong>Related:</strong>
    {{- $num_to_show := .Site.Params.relatedPostLimit | default 3 -}}
    {{ range first $num_to_show (where (where .Site.Pages ".Params.categories" "intersect"
    .Params.categories) "Permalink" "!=" .Permalink) }}

    {{ $postDateTimeSys := .Date.Format "2006-01-02T15:04:00Z" }}
{{ $postDateTime := .Date.Format "January 2, 2006" }}
    <p class="related-post">
        <a href="{{ .Permalink }}" class="u-url">
            <time class="dt-published" datetime="{{ $postDateTimeSys }}">{{ $postDateTime }}</time>
        </a>:
        <span class="p-name"><b>{{ .Title }}</b></span>
        <span class="p-summary">{{ .Summary | truncate 100 }}</span>
    </p>
    {{ end }}
</div>
{{ end }}
1 Like

I haven’t used this feature, but you are correct that Micro.blog does not support taxonomies other than categories. It looks like related content can use some other metadata like dates or even header titles based on the links, but that seems pretty low value to me.

1 Like