mirror of https://github.com/lxndrblz/anatole.git

Osterberg
27.17.2022 6ad4d7aea163240dbb76ed405125c7e3eeda2605
feat: Add option to display related posts (#300)

* Added an option to display related posts

Co-authored-by: Alexander Bilz <mail@alexbilz.com>
1 files added
3 files modified
30 ■■■■■ changed files
exampleSite/config/_default/config.toml 11 ●●●●● patch | view | raw | blame | history
exampleSite/config/_default/params.toml 3 ●●●●● patch | view | raw | blame | history
layouts/_default/single.html 5 ●●●●● patch | view | raw | blame | history
layouts/partials/related.html 11 ●●●●● patch | view | raw | blame | history
exampleSite/config/_default/config.toml
@@ -32,3 +32,14 @@
    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
exampleSite/config/_default/params.toml
@@ -27,6 +27,9 @@
# 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'
layouts/_default/single.html
@@ -57,6 +57,11 @@
      {{- end -}}
      {{- if (eq .Site.Params.relatedPosts true) -}}
        {{- partial "related.html" . -}}
      {{- end -}}
      {{- if (eq .Params.contact true) -}}
        {{- partial "contact.html" . -}}
layouts/partials/related.html
New file
@@ -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 }}