aboutsummaryrefslogtreecommitdiff
path: root/layouts
diff options
context:
space:
mode:
authorTrack3 <34504964+Track3@users.noreply.github.com>2019-06-21 13:15:53 +0800
committerGitHub <noreply@github.com>2019-06-21 13:15:53 +0800
commit6cee5adc69ed07b38786f0ad2512c2a4faf31063 (patch)
treedcb63feb11d0c3926dd98b1c41dbb9c93f5914de /layouts
parente333628a2663020701e058da5e15ae39ffc796bf (diff)
downloadhermit-6cee5adc69ed07b38786f0ad2512c2a4faf31063.tar.gz
Add related content section to single page (#77)
Set `relatedPosts` to `true` in the config to enable this.
Diffstat (limited to 'layouts')
-rw-r--r--layouts/partials/related-posts.html11
-rw-r--r--layouts/posts/single.html3
2 files changed, 14 insertions, 0 deletions
diff --git a/layouts/partials/related-posts.html b/layouts/partials/related-posts.html
new file mode 100644
index 0000000..d533bfd
--- /dev/null
+++ b/layouts/partials/related-posts.html
@@ -0,0 +1,11 @@
+{{- $related := .Site.RegularPages.Related . | first 5 }}
+{{ with $related }}
+<div class="related-posts thin">
+ <h2>{{ i18n "seeAlso" }}</h2>
+ <ul>
+ {{ range . }}
+ <li><a href="{{ .RelPermalink }}">{{ .Title }}</a></li>
+ {{ end }}
+ </ul>
+</div>
+{{ end -}}
diff --git a/layouts/posts/single.html b/layouts/posts/single.html
index 9557916..53c0818 100644
--- a/layouts/posts/single.html
+++ b/layouts/posts/single.html
@@ -25,6 +25,9 @@
<div class="content">
{{ .Content | replaceRE "(<h[1-6] id=\"([^\"]+)\".+)(</h[1-6]+>)" `${1}<a href="#${2}" class="anchor" aria-hidden="true"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M15 7h3a5 5 0 0 1 5 5 5 5 0 0 1-5 5h-3m-6 0H6a5 5 0 0 1-5-5 5 5 0 0 1 5-5h3"></path><line x1="8" y1="12" x2="16" y2="12"></line></svg></a>${3}` | safeHTML }}
</div>
+ {{- if .Site.Params.relatedPosts }}
+ {{- partial "related-posts.html" . -}}
+ {{- end }}
<hr class="post-end">
<footer class="post-info">
{{- with .Params.tags }}