arrow_back
Back

Hugo related content: keywords, Related, and related indices

Andrew Dorokhov Andrew Dorokhov schedule 1 min read
menu_book Table of Contents

Add keywords (or other indexed fields) to front matter:

keywords:
- technologies

In the layout:

<section class="related">
{{ $related := .Site.RegularPages.Related . | first 5 }}
{{ with $related }}
  <h3>Related pages</h3>
  <ul>
    {{ range . }}
    <li><a href="{{ .RelPermalink }}">{{ .Title }}</a></li>
    {{ end }}
  </ul>
{{ end }}
</section>

with skips the block when nothing related is found.

Settings

Default indices use keywords and dates. Customize in config.toml:

[related]
threshold = 80.0
includeNewer = false
toLower = false

[[related.indices]]
name = "keywords"
weight = 100.00

[[related.indices]]
name = "date"
weight = 10.00
  • includeNewer = true — older pages can pick up newer related content.
  • threshold — 0–100; lower values show more, less relevant matches.
  • toLower — lowercases keywords/queries to increase matches.
  • weight — relative importance of each index.

You can add indices for tags, author, or any other front-matter field.

code

Need Help with Development?

Happy to help — reach out via the contacts or go straight to my Upwork profile.

work View Upwork Profile arrow_forward
Next Article

Hugo pagination: Paginator, page size, and Bootstrap markup

arrow_forward