I would like to remove pages related by ‘date’ from the Related Content.
I am following the instructions in the docs: Related | Hugo , Related content | Hugo .
But whatever I do, the related content shows more pages than I expect.
My goal:
To display only content related by keywords.
What I tried:
I understand that I need to customize the default configuration.
Tried only leaving the block for keywords, hugo.yaml
:
related:
includeNewer: false
indices:
- applyFilter: false
cardinalityThreshold: 0
name: keywords
pattern: ""
toLower: false
type: basic
weight: 100
threshold: 80
toLower: false
And tried to leave the blocks for ‘date’, ‘tags’ but set their weight to 0 or -1.
Front matter:
In post1.md, project1.md:
keywords:
- mykeyword
Template:
{{ $opts := dict
"document" .
"indices" (slice "keywords")
}}
{{ with .Site.RegularPages.Related $opts | first 5 }}
<h3>Related pages:</h3>
<ul>
{{ range . }}
<li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
{{ end }}
</ul>
{{ end }}
Result
Post1 in browser shows the Related Content correctly, one page:
-project1
(Which must mean I am doing Something right.)
All other posts show a lot of related content (2-5 pages), including the Contact and About pages.
Only the post1, project1 front matter have the keyword set. There are other tags set throughout the site. In Contact, About no tags only date. Hence my thoughts, that even the date is pulled in for the Related Content.
Expected result:
Only post1 should show the related page: project1.
As those are the only ones linked with the keyword.
Other post pages should not have related pages.
With only keywords set in the ‘related’ block in hugo.yaml
and/or using options dict "indices" (slice "keywords")
in the template.
What am I missing? Please suggest.
(hugo v0.136.5-46cccb021bc6425455f4eec093f5cc4a32f1d12c+extended)