1
0
mirror of https://github.com/alanorth/hugo-theme-bootstrap4-blog.git synced 2024-11-24 21:20:17 +01:00

Use .Site.Params.mainSections instead of hard coding "post" type

Hugo 0.32 or so added the quasi-magical .Site.Params.mainSections slice
that returns a range over the section that has the most number of pages.

This way we don't need to hard code the "post" type, and instead simply
use the pages that the user has created. Hugo's quickstart, for example,
recommends users create "posts", which currently doesn't work with this
theme!

Closes #89
This commit is contained in:
Alan Orth 2018-03-09 17:50:03 +02:00
parent 99acad59bc
commit 1655b876a8
Signed by: alanorth
GPG Key ID: 0FB860CC9C45B1B9
3 changed files with 2 additions and 9 deletions

View File

@ -37,17 +37,10 @@
<nav class="nav blog-nav"> <nav class="nav blog-nav">
<a class="nav-link {{ if .IsHome }}active{{ end }}" href="{{ .Site.BaseURL | absLangURL }}">{{ i18n "home" }}</a> <a class="nav-link {{ if .IsHome }}active{{ end }}" href="{{ .Site.BaseURL | absLangURL }}">{{ i18n "home" }}</a>
{{- $currentURL := .URL | absLangURL -}} {{- $currentURL := .URL | absLangURL -}}
{{ if .Site.Params.custom_navbar }}
{{ range .Site.Menus.navbar }} {{ range .Site.Menus.navbar }}
{{ $menuURL := .URL | absLangURL }} {{ $menuURL := .URL | absLangURL }}
<a class="nav-link{{ if eq $menuURL $currentURL }} active{{ end }}" href="{{.URL | absURL }}">{{ .Name }}</a> <a class="nav-link{{ if eq $menuURL $currentURL }} active{{ end }}" href="{{.URL | absURL }}">{{ .Name }}</a>
{{ end }} {{ end }}
{{ else }}
{{ range where .Site.RegularPages "Type" "!=" "post" }}
{{ $permalinkURL := .Permalink | absLangURL }}
<a class="nav-link{{ if eq $permalinkURL $currentURL }} active{{ end }}" href="{{ .Permalink }}">{{ .Title }}</a>
{{ end }}
{{ end }}
</nav> </nav>
</div> </div>
</div> </div>

View File

@ -30,7 +30,7 @@
{{ define "main" }} {{ define "main" }}
{{ $truncate := default true .Site.Params.truncate }} {{ $truncate := default true .Site.Params.truncate }}
{{ $paginator := .Paginate (where .Data.Pages "Type" "post") }} {{ $paginator := .Paginate (where .Site.Pages "Section" "in" .Site.Params.mainSections) }}
{{ range $paginator.Pages }} {{ range $paginator.Pages }}
{{ if $truncate }} {{ if $truncate }}
{{ .Render "summary" }} {{ .Render "summary" }}

View File

@ -2,7 +2,7 @@
<h4>{{ i18n "recentPosts" }}</h4> <h4>{{ i18n "recentPosts" }}</h4>
<ol class="list-unstyled"> <ol class="list-unstyled">
{{ $num_recent_posts := (index .Site.Params.sidebar "num_recent_posts" | default 5) }} {{ $num_recent_posts := (index .Site.Params.sidebar "num_recent_posts" | default 5) }}
{{ range first $num_recent_posts (where .Site.RegularPages "Type" "post") }} {{ range first $num_recent_posts (where .Site.Pages "Section" "in" .Site.Params.mainSections) }}
<li><a href="{{.RelPermalink}}">{{.Title | markdownify }}</a></li> <li><a href="{{.RelPermalink}}">{{.Title | markdownify }}</a></li>
{{ end }} {{ end }}
</ol> </ol>