Skip to content

Commit

Permalink
✨ Feat: add hiddenFromRelated page param and reduce the scope of rele…
Browse files Browse the repository at this point in the history
…ated content to posts (#227)
  • Loading branch information
Lruihao committed Dec 20, 2023
1 parent e436758 commit 4342d40
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions archetypes/post-bundle/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ categories:
hiddenFromHomePage: false
hiddenFromSearch: false
hiddenFromRss: false
hiddenFromRelated: false
summary:
resources:
- name: featured-image
Expand Down
1 change: 1 addition & 0 deletions archetypes/posts.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ categories:
hiddenFromHomePage: false
hiddenFromSearch: false
hiddenFromRss: false
hiddenFromRelated: false
summary:
resources:
- name: featured-image
Expand Down
4 changes: 3 additions & 1 deletion hugo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,8 @@ enableEmoji = true
hiddenFromSearch = false
# FixIt 0.2.18-lts.5 | NEW whether to hide a page from RSS feed
hiddenFromRss = false
# FixIt 0.3.0 | NEW whether to hide a page from related posts
hiddenFromRelated = false
# FixIt 0.2.0 | NEW whether to enable twemoji
twemoji = false
# whether to enable lightgallery
Expand Down Expand Up @@ -699,7 +701,7 @@ enableEmoji = true
name = ""
logoUrl = ""

# FixIt 0.3.0 | NEW Related content config
# FixIt 0.3.0 | NEW Related content config (https://gohugo.io/content-management/related/)
[params.page.related]
enable = false
count = 5
Expand Down
8 changes: 7 additions & 1 deletion layouts/partials/single/related.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
{{- $params := .Scratch.Get "params" -}}

{{- if $params.related.enable -}}
{{- $related := .Site.RegularPages.Related . | first ($params.related.count | default 5) -}}
{{- $posts := where .Site.RegularPages "Type" "posts" -}}
{{- if .Site.Params.page.hiddenFromRelated -}}
{{- $posts = where $posts "Params.hiddenfromrelated" false -}}
{{- else -}}
{{- $posts = where $posts "Params.hiddenfromrelated" "!=" true -}}
{{- end -}}
{{- $related := $posts.Related . | first ($params.related.count | default 5) -}}
{{- with $related -}}
<h2 id="see-also">{{ T "single.relatedContent" }}</h2>
<ul>
Expand Down

0 comments on commit 4342d40

Please sign in to comment.