From 6cee5adc69ed07b38786f0ad2512c2a4faf31063 Mon Sep 17 00:00:00 2001 From: Track3 <34504964+Track3@users.noreply.github.com> Date: Fri, 21 Jun 2019 13:15:53 +0800 Subject: [PATCH] Add related content section to single page (#77) Set `relatedPosts` to `true` in the config to enable this. --- assets/scss/style.scss | 19 +++++++++++++++++++ exampleSite/config.toml | 2 ++ i18n/en.toml | 3 +++ i18n/zh-hans.toml | 3 +++ layouts/partials/related-posts.html | 11 +++++++++++ layouts/posts/single.html | 3 +++ ...s_c16d144eee185fbddd582cd5e25a4fae.content | 2 +- ...scss_c16d144eee185fbddd582cd5e25a4fae.json | 2 +- 8 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 layouts/partials/related-posts.html diff --git a/assets/scss/style.scss b/assets/scss/style.scss index 32c6ee6..a58003f 100644 --- a/assets/scss/style.scss +++ b/assets/scss/style.scss @@ -687,6 +687,25 @@ hr.post-end { } } +.related-posts { + padding: .8em; + margin-top: 1.5em; + font-size: .8rem; + border: 3px dashed rgba(255, 255, 255, .2); + border-radius: 5px; + + h2{ + margin: 0; + line-height: normal; + } + + ul { + margin-top: .5em; + margin-bottom: 0; + } +} + + // Media Queries // @media (min-width: 800px) { diff --git a/exampleSite/config.toml b/exampleSite/config.toml index 1f8be3b..3c94862 100644 --- a/exampleSite/config.toml +++ b/exampleSite/config.toml @@ -46,6 +46,8 @@ enableEmoji = true # Shorthand emojis in content files - https://gohugo.io/func # Toggling this option needs to rebuild SCSS, requires Hugo extended version justifyContent = false # Set "text-align: justify" to `.content`. + relatedPosts = false # Add a related content section to all single posts page + # Add custom css # customCSS = ["css/foo.css", "css/bar.css"] diff --git a/i18n/en.toml b/i18n/en.toml index 1b09bfc..e68038a 100644 --- a/i18n/en.toml +++ b/i18n/en.toml @@ -14,6 +14,9 @@ other = "Archives" # posts/single.html # +[seeAlso] +other = "See Also" + [wordCount] other = "{{ .WordCount }} Words" diff --git a/i18n/zh-hans.toml b/i18n/zh-hans.toml index 8884b93..b9c064a 100644 --- a/i18n/zh-hans.toml +++ b/i18n/zh-hans.toml @@ -14,6 +14,9 @@ other = "归档" # posts/single.html # +[seeAlso] +other = "相关推荐" + [wordCount] other = "{{ .WordCount }} 字" 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 }} + +{{ 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 @@
{{ .Content | replaceRE "()" `${1}${3}` | safeHTML }}
+ {{- if .Site.Params.relatedPosts }} + {{- partial "related-posts.html" . -}} + {{- end }}