From 9e562fc076bf8869d6c513d34f7e120dedb63193 Mon Sep 17 00:00:00 2001 From: George Cushen Date: Wed, 27 May 2020 01:23:10 +0100 Subject: [PATCH] feat: add `show_related` option to control related content The following option has been added to `params.toml` to control related content on pages: `show_related = {docs = true, page = false, post = true, project = true, publication = true, talk = true}` --- exampleSite/config/_default/config.toml | 32 +++++++++++++++++++++++-- exampleSite/config/_default/params.toml | 9 ++++++- layouts/partials/docs_layout.html | 2 ++ layouts/partials/page_footer.html | 14 +---------- layouts/partials/page_related.html | 13 ++++++++++ 5 files changed, 54 insertions(+), 16 deletions(-) create mode 100644 layouts/partials/page_related.html diff --git a/exampleSite/config/_default/config.toml b/exampleSite/config/_default/config.toml index ba89b491..81a24ea8 100644 --- a/exampleSite/config/_default/config.toml +++ b/exampleSite/config/_default/config.toml @@ -1,5 +1,6 @@ -# Configuration of Academic -# Documentation: https://sourcethemes.com/academic/ +# Configuration of Hugo +# Guide: https://sourcethemes.com/academic/docs/get-started/ +# Hugo Documentation: https://gohugo.io/getting-started/configuration/#all-configuration-settings # # This file is formatted using TOML syntax - learn more at https://learnxinyminutes.com/docs/toml/ # Each configuration section is defined by a name in square brackets (e.g. `[outputs]`). @@ -55,6 +56,7 @@ ignoreFiles = ["\\.ipynb$", ".ipynb_checkpoints$", "\\.Rmd$", "\\.Rmarkdown$", " mediaType = "application/manifest+json" rel = "manifest" +# Configure the Markdown renderer. [markup] defaultMarkdownHandler = "goldmark" [markup.goldmark] @@ -77,3 +79,29 @@ ignoreFiles = ["\\.ipynb$", ".ipynb_checkpoints$", "\\.Rmd$", "\\.Rmarkdown$", " category = "categories" publication_type = "publication_types" author = "authors" + +# Related content. +[related] + threshold = 80.0 + includeNewer = true + toLower = true + + [[related.indices]] + name = "title" + weight = 60.0 + + [[related.indices]] + name = "summary" + weight = 50.0 + + [[related.indices]] + name = "tags" + weight = 80.0 + + [[related.indices]] + name = "categories" + weight = 70.0 + + [[related.indices]] + name = "authors" + weight = 20.0 diff --git a/exampleSite/config/_default/params.toml b/exampleSite/config/_default/params.toml index 1dae6cbf..5e75935b 100644 --- a/exampleSite/config/_default/params.toml +++ b/exampleSite/config/_default/params.toml @@ -1,5 +1,9 @@ # SITE SETUP -# Documentation: https://sourcethemes.com/academic/ +# Guide: https://sourcethemes.com/academic/docs/get-started/ +# Documentation: https://sourcethemes.com/academic/docs/ +# +# This file is formatted using TOML syntax - learn more at https://learnxinyminutes.com/docs/toml/ +# Each configuration section is defined by a name in square brackets (e.g. `[search]`). ############################ ## Theme @@ -73,6 +77,9 @@ privacy_pack = false # `repo` defines the repository URL. `editable` defines which page types can be edited. edit_page = {repo_url = "https://github.com/gcushen/hugo-academic", content_dir = "", repo_branch = "master", editable = {docs = true, page = false, post = false}} +# Show related content at the bottom of pages? +show_related = {docs = true, page = false, post = true, project = true, publication = true, talk = true} + ############################ ## Contact details ## diff --git a/layouts/partials/docs_layout.html b/layouts/partials/docs_layout.html index bc80575d..cdf543c5 100644 --- a/layouts/partials/docs_layout.html +++ b/layouts/partials/docs_layout.html @@ -44,6 +44,8 @@ {{ partial "page_edit" . }} {{ partial "comments" . }} + + {{ partial "page_related" . }} diff --git a/layouts/partials/page_footer.html b/layouts/partials/page_footer.html index 244d2b5e..46691373 100644 --- a/layouts/partials/page_footer.html +++ b/layouts/partials/page_footer.html @@ -10,16 +10,4 @@ {{ end }} -{{ if ne .Type "page" }} - {{ $related := site.RegularPages.Related . | first 5 }} - {{ with $related }} -
-

{{ i18n "related" }}

- -
- {{ end }} -{{ end }} +{{ partial "page_related" . }} diff --git a/layouts/partials/page_related.html b/layouts/partials/page_related.html new file mode 100644 index 00000000..ecc1e6d0 --- /dev/null +++ b/layouts/partials/page_related.html @@ -0,0 +1,13 @@ +{{ if (index site.Params.show_related .Type) | and (ne .Params.show_related false) | or .Params.show_related }} + {{ $related := site.RegularPages.Related . | first 5 }} + {{ with $related }} +
+

{{ i18n "related" }}

+ +
+ {{ end }} +{{ end }}