From 7dd9793f03511608c5095fd4abeb0ac2767e7fae Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Fri, 24 Jul 2020 22:44:08 +0100 Subject: [PATCH] Add related content to pages Couldn't get it showing pages in the past, because Hugos docs on what the default are appear to be incorrect --- config.yml | 10 ++++++++++ layouts/_default/flickr.html | 1 + layouts/_default/single.html | 1 + layouts/_default/spotify.html | 1 + layouts/partials/related-content.html | 21 +++++++++++++++++++++ layouts/partials/share.html | 2 +- 6 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 layouts/partials/related-content.html diff --git a/config.yml b/config.yml index a9ca86f..f7f29fc 100644 --- a/config.yml +++ b/config.yml @@ -40,3 +40,13 @@ theme: - utils assetDir: static/build/ + +related: + threshold: 80 + includeNewer: false + toLower: false + indices: + - name: keywords + weight: 100 + - name: date + weight: 10 diff --git a/layouts/_default/flickr.html b/layouts/_default/flickr.html index 0f442b1..e18e7de 100644 --- a/layouts/_default/flickr.html +++ b/layouts/_default/flickr.html @@ -24,5 +24,6 @@ {{ partial "share.html" . }} + {{ partial "related-content.html" . }} {{ end }} diff --git a/layouts/_default/single.html b/layouts/_default/single.html index f704d82..faacd70 100644 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -4,5 +4,6 @@ {{ partial "content.html" . }} {{ partial "share.html" . }} + {{ partial "related-content.html" . }} {{ end }} diff --git a/layouts/_default/spotify.html b/layouts/_default/spotify.html index d1d947e..aa37d74 100644 --- a/layouts/_default/spotify.html +++ b/layouts/_default/spotify.html @@ -53,5 +53,6 @@ {{ partial "share.html" . }} + {{ partial "related-content.html" . }} {{ end }} diff --git a/layouts/partials/related-content.html b/layouts/partials/related-content.html new file mode 100644 index 0000000..abffc2b --- /dev/null +++ b/layouts/partials/related-content.html @@ -0,0 +1,21 @@ +{{ if .Section }} + {{ $pages := where .Site.RegularPages "Section" .Section }} + + {{ $related := ($pages.Related .) | first 3 }} + + {{ if $related }} + {{ $col := printf "col-md-%d" (div 12 (len $related)) }} + +
+

Related content

+
+ {{ range $related }} +
+
{{ .Title }}
+ {{ partial "content-details.html" . }} +
+ {{ end }} +
+
+ {{ end }} +{{ end }} diff --git a/layouts/partials/share.html b/layouts/partials/share.html index 02c2a00..9038429 100644 --- a/layouts/partials/share.html +++ b/layouts/partials/share.html @@ -1,5 +1,5 @@ {{ if .Section }} -
+
Share this page