From 8d4b1bb7f0947de034575aa300e43725a25a6bfa Mon Sep 17 00:00:00 2001 From: Dominic Reich Date: Wed, 18 Dec 2024 10:34:57 +0100 Subject: [PATCH] adds related articles to single article view --- config/_default/config.toml | 21 ++++++++++ layouts/_default/single.html | 75 +++++++++++++++++++++++++++++++++++ layouts/partials/related.html | 11 +++++ 3 files changed, 107 insertions(+) create mode 100644 layouts/_default/single.html create mode 100644 layouts/partials/related.html diff --git a/config/_default/config.toml b/config/_default/config.toml index 4148a79..8863018 100644 --- a/config/_default/config.toml +++ b/config/_default/config.toml @@ -107,3 +107,24 @@ page = [ "HTML" ] taxonomy = [ "HTML" ] #taxonomyTerm = [ "HTML" ] +[related] + includeNewer = true + threshold = 80 + toLower = false + + [[related.indices]] + name = "title" + weight = 30 + + [[related.indices]] + name = "summary" + weight = 30 + + [[related.indices]] + name = "tags" + weight = 30 + + [[related.indices]] + name = "date" + weight = 10 + diff --git a/layouts/_default/single.html b/layouts/_default/single.html new file mode 100644 index 0000000..025fa1d --- /dev/null +++ b/layouts/_default/single.html @@ -0,0 +1,75 @@ +{{ define "main" }} + {{- $images := .Resources.ByType "image" }} + {{- $cover := $images.GetMatch (.Params.cover | default "*cover*") }} + {{- $feature := $images.GetMatch (.Params.feature | default "*feature*") | default $cover }} +
+
+ {{ if .Params.showBreadcrumbs | default (.Site.Params.article.showBreadcrumbs | default false) }} + {{ partial "breadcrumbs.html" . }} + {{ end }} +

+ {{ .Title | emojify }} +

+ {{ if or + (.Params.showDate | default (.Site.Params.article.showDate | default true)) + (and (.Params.showDateUpdated | default (.Site.Params.article.showDateUpdated | default false)) (ne (partial "functions/date.html" .Date) (partial "functions/date.html" .Lastmod))) + (and (.Params.showWordCount | default (.Site.Params.article.showWordCount | default false)) (ne .WordCount 0)) + (and (.Params.showReadingTime | default (.Site.Params.article.showReadingTime | default true)) (ne .ReadingTime 0)) + (.Params.showEdit | default (.Site.Params.article.showEdit | default false)) + }} +
+ {{ partial "article-meta.html" (dict "context" . "scope" "single") }} +
+ {{ end }} + {{ with $feature }} +
+ {{ $altText := $.Params.featureAlt | default $.Params.coverAlt | default "" }} + {{ $class := "mb-6 rounded-md" }} + {{ $webp := $.Page.Site.Params.enableImageWebp | default true }} + {{ partial "picture.html" (dict "img" . "alt" $altText "class" $class "lazy" false "webp" $webp) }} + {{ with $.Params.coverCaption }} +
{{ . | markdownify }}
+ {{ end }} +
+ {{ end }} +
+
+ {{ if and (.Params.showTableOfContents | default (.Site.Params.article.showTableOfContents | default false)) (in .TableOfContents " +
+ {{ partial "toc.html" . }} +
+ + {{ end }} +
+ {{ .Content | emojify }} +
+
+
+ {{ partial "author.html" . }} + +
+
+ {{ partial "related.html" . }} +
+
+ + {{ partial "sharing-links.html" . }} + {{ partial "article-pagination.html" . }} + + {{ if .Params.showComments | default (.Site.Params.article.showComments | default false) }} + {{ if templates.Exists "partials/comments.html" }} +
+
+
+ {{ partial "comments.html" . }} +
+
+ {{ else }} + {{ warnf "[CONGO] Comments are enabled for %s but no comments partial exists." .File.Path }} + {{ end }} + {{ end }} +
+
+{{ end }} + diff --git a/layouts/partials/related.html b/layouts/partials/related.html new file mode 100644 index 0000000..1ca1c4d --- /dev/null +++ b/layouts/partials/related.html @@ -0,0 +1,11 @@ +{{ $related := .Site.RegularPages.Related . | first 5 }} {{ with $related }} +

Related Posts

+ +{{ end }}