Skip to content

Commit

Permalink
feat: Add option to display related posts (#300)
Browse files Browse the repository at this point in the history
* Added an option to display related posts

Co-authored-by: Alexander Bilz <mail@alexbilz.com>
  • Loading branch information
gummigroda and lxndrblz committed Mar 27, 2022
1 parent 4c83061 commit 6ad4d7a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
11 changes: 11 additions & 0 deletions exampleSite/config/_default/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,14 @@ pygmentsCodefencesGuessSyntax = true
category = "categories"
series = "series"
tag = "tags"

[related]
includeNewer = true
threshold = 80
toLower = true
[[related.indices]]
name = 'keywords'
weight = 100
[[related.indices]]
name = 'tags'
weight = 80
3 changes: 3 additions & 0 deletions exampleSite/config/_default/params.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ listDateFormat = "2/1/2006"
# Read More links for truncated summaries
# readMore = true
# postSectionName = "blog"
# relatedPosts = true
# numberOfRelatedPosts = 3


reversepagetitle = true # When set to 'true', the Window Title will be reversed to 'Title | Author' instead of the default 'Author | Title'

Expand Down
5 changes: 5 additions & 0 deletions layouts/_default/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ <h3>Table of Contents</h3>

{{- end -}}

{{- if (eq .Site.Params.relatedPosts true) -}}
{{- partial "related.html" . -}}

{{- end -}}

{{- if (eq .Params.contact true) -}}
{{- partial "contact.html" . -}}

Expand Down
11 changes: 11 additions & 0 deletions layouts/partials/related.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{ $related := .Site.RegularPages.Related . | first .Site.Params.numberOfRelatedPosts }}
{{ with $related }}
<h3>Related Posts</h3>
<ul>
{{ range . }}
<li><a href="{{ .RelPermalink }}">{{ .Title }}</a></li>

{{ end }}
</ul>

{{ end }}

0 comments on commit 6ad4d7a

Please sign in to comment.