Paginate with an extra item on the first page?

I’m building a blog template that has a “featured” article, then X number of regular articles (lets say 6). Then pagination should have 6 more articles on each subsequent page. If I set paginate = 6 in the config, it all works fine except for the main page, which has the featured + 5 more. In a standard 3 columns per row grid, this doesn’t look good to have 5 entries.

Anyway I can override a single page to have Paginate+1?

Rough index.html as follows:

{{ define "main" }}
{{ $pages := where .Site.RegularPages "Type" "in" .Site.Params.mainSections }}
{{ $pag := .Paginate (where $pages "Params.hidden" "ne" true) }}
{{ $s := newScratch }}
{{ $s.Set "offset" "0" }}
<main class="homepage">
    {{ if not $pag.HasPrev }}
    {{ $s.Set "offset" "1" }}

    <!-- Hero -->
    {{ partial "hero.html" . }}

    <!-- Featured article -->
    {{ partial "featured.html" . }}
    {{ end }}
    <!-- Articles -->
    <div class="articles row row-cols-1 row-cols-lg-3">
        {{ $offset := $s.Get "offset" }}
        {{ range after $offset ($pag.Pages)}}
        <div class="col mb-3">
            {{ .Render "card" }}
        {{ end }}
    <div class="paginator row row-cols-1">
        {{ template "partials/paginator.html" . }}
{{ end }}

You can override the global page size setting:

Got it. Does work, but how do I increment the existing value? I can’t simple add 1 .Paginator.Pages

For my own personal usage, I could hard code everything, but trying to make it nice and user friendly.

Ok. In the end I realized it doesn’t matter. If I try to apply some logic like if eq .Paginator.PageNumber 1 then set number to X+1 else X… it doesn’t work. As soon as I invoke .Paginator.PageNumber the Paginator is created with the default values and I can’t override them.

So TLDR: I need to setup param in the config for front page count, separate from the regular paginator value.

… However this doesn’t work either because I have no way to detect that I’m on the homepage and NOT paginated. .isHome is always true… and I can’t use pagination or else I can’t override it. I’m lost, there has to be a solution here I’m not seeing.

So, you want your featured page to count towards the pages of the first paginator page?

Page 1

Page 2

Page 3

where F is your featured page and X a regular page?

You could just add your featured page to the front of your pages to paginate. You would also need to make changes to how you render your featured page.

{{ $featuredpage := site.GetPage "yourfeaturedpage" }}
{{ $pages := slice ($featuredpage) }}
{{ $pages = $pages | append site.RegularPages }} <!-- add your other pages -->

{{ $paginator := .Paginate $pages }}
{{ template "_internal/pagination.html" . }} <!-- use your pagination template -->

    {{ range $paginator.Pages }}
        {{ if eq .Page $featuredpage  }}
        featured page here: {{.Page}}
        {{ else }}
        not a featured page: {{.Page}}
        {{ end }}
    {{ end }}
1 Like