1
0
mirror of https://github.com/alanorth/hugo-theme-bootstrap4-blog.git synced 2024-12-25 03:34:29 +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">
<a class="nav-link {{ if .IsHome }}active{{ end }}" href="{{ .Site.BaseURL | absLangURL }}">{{ i18n "home" }}</a>
{{- $currentURL := .URL | absLangURL -}}
{{ if .Site.Params.custom_navbar }}
{{ range .Site.Menus.navbar }}
{{ $menuURL := .URL | absLangURL }}
<a class="nav-link{{ if eq $menuURL $currentURL }} active{{ end }}" href="{{.URL | absURL }}">{{ .Name }}</a>
{{ 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>
</div>
</div>

View File

@ -30,7 +30,7 @@
{{ define "main" }}
{{ $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 }}
{{ if $truncate }}
{{ .Render "summary" }}

View File

@ -2,7 +2,7 @@
<h4>{{ i18n "recentPosts" }}</h4>
<ol class="list-unstyled">
{{ $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>
{{ end }}
</ol>