1
0
mirror of https://github.com/alanorth/hugo-theme-bootstrap4-blog.git synced 2024-06-26 16:13:45 +02:00

Allow configuration of recent posts on sidebar

By default it shows the latest five posts, but you can set this
property in your config to override it:

  [params.sidebar]
    num_recent_posts = 7

Still no way to disable it, as I don't understand golang's HTML
templating stuff yet. The Hugo docs are a bit confusing, but it
seems like conditionals are a bit tricky because both false and
0 return a boolean false... hmm.

See: https://gohugo.io/templates/go-templates/
This commit is contained in:
Alan Orth 2016-09-07 23:54:55 +03:00
parent ba25b91d94
commit d214834089
Signed by: alanorth
GPG Key ID: 0FB860CC9C45B1B9

View File

@ -6,16 +6,16 @@
</section>
{{ end }}
{{ if isset .Site.Params.sidebar "num_recent_posts" }}
{{ $num_recent_posts := (index .Site.Params.sidebar "num_recent_posts" | default 5) }}
<section class="sidebar-module">
<h4>Recent Posts</h4>
<ol class="list-unstyled">
{{ range first .Site.Params.sidebar.num_recent_posts .Site.Pages }}
{{ range first $num_recent_posts .Site.Pages }}
<li><a href="{{.RelPermalink}}">{{.Title}}</a></li>
{{ end }}
</ol>
</section>
{{ end }}
<section class="sidebar-module">
<h4>Elsewhere</h4>