fix: paginate recent posts and use params.mainSections

This commit is contained in:
Vivek R
2019-09-10 00:12:59 +05:30
parent 0e06bb53c5
commit bb28e76551
7 changed files with 84 additions and 40 deletions

View File

@@ -7,7 +7,7 @@
{{ partial "head.html" . }}
{{ if isset .Data "Term" }}
<h1>Entries tagged - "{{.Data.Term}}"</h1>
<h1>Entries tagged - "{{ .Data.Term }}"</h1>
{{ else }}
<h1 class="page-title">All articles</h1>
{{ end }}

View File

@@ -16,7 +16,7 @@
{{- $.Scratch.Set "isDisqus" true -}}
{{- if and (isset .Params "type") (in (.Site.Params.disableDisqusTypes | default (slice "page")) .Params.type) -}}
{{- if and (isset .Params "type") (in .Site.Params.disableDisqusTypes .Params.type) -}}
{{- $.Scratch.Set "isDisqus" false -}}
{{- end -}}

View File

@@ -10,30 +10,24 @@
Recent posts
</h2>
<div class="posts">
{{- $.Scratch.Set "counter" 0 -}}
{{- range .Data.Pages -}}
{{- if (in (.Site.Params.excludedTypes | default (slice "page")) .Type) -}}
{{- else -}}
{{- if lt ($.Scratch.Get "counter") (.Site.Params.RecentPostsCount | default 10) -}}
{{ $pages := where site.RegularPages "Type" "in" site.Params.mainSections }}
{{ $paginator := .Paginate (where $pages "Params.hidden" "ne" true) }}
{{ range $paginator.Pages }}
<div class="post">
<div class="meta">{{ dateFormat "Jan 2, 2006" .Date }}</div>
<a class="title" href="{{ .RelPermalink }}">{{.Title}}</a> &mdash;
<span class="description">
{{ if isset .Params "description" }}
{{ .Description }}
{{ .Description }}
{{ else if gt (len .RawContent) 120 }}
{{ slicestr .RawContent 0 120 }}...
{{ slicestr .RawContent 0 120 }}...
{{ else }}
{{ .RawContent }}
{{ .RawContent }}
{{ end }}
</span>
</div>
{{- $.Scratch.Set "counter" (add ($.Scratch.Get "counter") 1) -}}
{{- end -}}
{{- end -}}
{{- end -}}
<a href="/posts">All articles →</a>
{{ end }}
{{ template "partials/paginator.html" . }}
</div>
</div>
</div>

View File

@@ -0,0 +1,15 @@
{{ $pag := $.Paginator }}
{{ if gt $pag.TotalPages 1 }}
<ul class="pagination">
<li class="page-item page-prev">
{{ if $pag.HasPrev }}
<a {{ if $pag.HasPrev }}href="{{ $pag.Prev.URL }}"{{ end }} class="page-link" aria-label="Previous"><span aria-hidden="true">← Prev page</span></a>
{{ end }}
</li>
<li class="page-item page-next">
{{ if $pag.HasNext }}
<a {{ if $pag.HasNext }}href="{{ $pag.Next.URL }}"{{ end }} class="page-link" aria-label="Next"><span aria-hidden="true">Next page →</span></a>
{{ end }}
</li>
</ul>
{{ end }}