Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve series functionality #432

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion exampleSite/config/_default/params.toml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ blogDir = "post"
# notice of the footer.
# since = 2016

# Show related content at the end of an article based on the 'series' taxonomy. Can be set in post front matter.
# Show related content at the end of an article or in the sidebar, based on the 'series' taxonomy.
# Both parameters can be overridden in the post's front matter.
# showRelatedInArticle = false
# showRelatedInSidebar = false

Expand Down
6 changes: 4 additions & 2 deletions exampleSite/content/post/bundle/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ categories:
- syntax
tags:
- Hugo
series:
- Themes Guide
series: Themes Guide
# the following overrides the settings from params.toml:
showRelatedInArticle: true
showRelatedInSidebar: true
---

[Page bundles](https://gohugo.io/content-management/page-bundles/) are an optional way to [organize page resources](https://gohugo.io/content-management/page-resources/) within Hugo.
Expand Down
2 changes: 1 addition & 1 deletion exampleSite/content/post/markdown-syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ categories = [
"themes",
"syntax",
]
series = ["Themes Guide"]
series = "Themes Guide"
aliases = ["migrate-from-jekyl"]
thumbnail = "images/building.png"
+++
Expand Down
2 changes: 1 addition & 1 deletion exampleSite/content/post/markdown-syntax.pt.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ categories = [
"temas",
"sintaxe",
]
series = ["Guia de Temas"]
series = "Guia de Temas"
aliases = ["migrar-de-jekyl"]
thumbnail = "images/building.png"
+++
Expand Down
8 changes: 4 additions & 4 deletions layouts/_default/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ <h2>{{ T "overview" }}</h2>
{{- .Content }}
</div>

{{- $showRelatedInArticle := true }}
{{- if eq $s.showRelatedInArticle false }}
{{- $showRelatedInArticle = false }}
{{- $showRelatedInArticle := $s.showRelatedInArticle }}
{{- if eq $p.showRelatedInArticle true }}
{{- $showRelatedInArticle = true }}
{{- else if eq $p.showRelatedInArticle false }}
{{- $showRelatedInArticle = false }}
{{- end }}
{{- if ne $showRelatedInArticle false }}
{{- if (and ($showRelatedInArticle) (isset $p "series")) }}
{{- partial "related" . }}
{{- end }}

Expand Down
12 changes: 6 additions & 6 deletions layouts/partials/related.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{{ if isset .Params "series" }}
{{$related := where .Site.RegularPages ".Params.series" "eq" .Params.series }}
<h2 class="post_related">{{ T "series_posts" }}</h2>
<ul>
{{ range $related }}
<li><a href="{{ .Permalink }}" class="nav-link" title="{{ .Title }}">{{ .Title }}</a></li>
{{ end }}
</ul>
<h2 class="post_related">{{ T "series_posts" }}</h2>
<ul>
{{ range sort $related "Date" }}
<li><a href="{{ .Permalink }}" class="nav-link" title="{{ .Title }}">{{ .Title }}</a></li>
{{ end }}
</ul>
{{ end }}
16 changes: 9 additions & 7 deletions layouts/partials/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,23 @@ <h2 class="mt-4">Disclaimer</h2>
</div>
{{ end }}

{{- $relatedInSidebar := true }}
{{- if eq $s.showRelatedInSidebar false }}
{{ $relatedInSidebar = false }}
{{- $showRelatedInSidebar := $s.showRelatedInSidebar }}
{{- if eq .Params.showRelatedInSidebar true }}
{{- $showRelatedInSidebar = true }}
{{- else if eq .Params.showRelatedInSidebar false }}
{{- $showRelatedInSidebar = false }}
{{- end }}
{{ if (and ($relatedInSidebar) (isset .Params "series") ) }}
{{- if (and ($showRelatedInSidebar) (isset .Params "series")) }}
{{$related := where .Site.RegularPages ".Params.series" "eq" .Params.series }}
<h2 class="mt-4">{{ T "series_posts" }}</h2>
<h2 class="mt-4">{{ T "series_posts" }}</h2>
<ul>
{{ range $related }}
{{ range sort $related "Date" }}
<li>
<a href="{{ .Permalink }}" class="nav-link" title="{{ .Title }}">{{ .Title | markdownify }}</a>
</li>
{{ end }}
</ul>
{{ end }}
{{- end }}

{{- $posts := where .Site.RegularPages "Type" "in" $s.mainSections }}
{{- $featured := default 8 $s.numberOfFeaturedPosts }}
Expand Down