Skip to content

Commit

Permalink
awesome new pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
dhonus committed Apr 6, 2024
1 parent 86d2cc3 commit 424acf9
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 15 deletions.
23 changes: 23 additions & 0 deletions assets/style.sass
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,29 @@ nav.pagination
background: inherit
color: gray
cursor: default
ul.pages
display: flex
flex-direction: row
gap: .2rem
margin: 0 .6rem
padding: 0
a
display: inline-block
line-height: 2rem
font-size: 1.2rem
padding: 0 .5rem
&.active
background: #e6dfcd
color: $link
a.disabled
color: gray
cursor: default
&:hover
background: inherit
color: gray
li.active
background: #e6dfcd
color: $link

// .category_container:first-of-type
// margin-left: 5px
Expand Down
18 changes: 16 additions & 2 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ baseURL = 'tofudreams.com/'
languageCode = 'en-us'
title = 'Tofu Dreams'
description = "Vegan recipes to dream about"
copyright = "2023 Tofu Dreams"
copyright = "2024 Tofu Dreams"
theme = 'bean'

relativeURLs = true
Expand All @@ -20,9 +20,23 @@ capitalizeListTitles = false
[menu]
[[menu.main]]
name = "Home"
pre = "home"
url = "/"
weight = 1
[[menu.main]]
name = "Savory"
pre = "savory"
pageref = "/categories/savory/"
weight = 2
[[menu.main]]
name = "Sweet"
pre = "sweet"
pageref = "/categories/sweet/"
weight = 3
[[menu.main]]
name = "Oatmeal"
pre = "oatmeal"
pageref = "/categories/oatmeal/"
weight = 4

[params]
logo = "logo.png"
Expand Down
49 changes: 40 additions & 9 deletions themes/bean/layouts/_default/taxonomy.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,46 @@ <h1>{{ $title }}</h1>
</div>

<nav class="pagination">
{{ if .Paginator.HasPrev }}
<a class="prev" href="{{ if .Paginator.HasPrev }}{{ .Paginator.Prev.URL }}{{ else }}#{{ end }}">« Prev</a>
{{ else }}
<p class="prev">« Prev</p>
{{ end }}
{{ if .Paginator.HasNext }}
<a class="next" href="{{ if .Paginator.HasNext }}{{ .Paginator.Next.URL }}{{ else }}#{{ end }}">Next »</a>
{{ else }}
<p class="next">Next »</p>
{{ $pag := $.Paginator }}
{{ $window := $.Site.Params.paginateWindow | default 1 }}
{{ if gt $pag.TotalPages 1 }}
{{ $total := $pag.TotalPages }}
{{ $size := add 5 (add $window $window) }}
{{ $cur := $pag.PageNumber }}
{{ if gt $total $size }}
{{ if lt $cur (sub $size (add $window 1)) }}
{{ $.Scratch.Set "show" (seq 1 (sub $size 2)) }}
{{ else if lt (sub $total $cur) (sub $size (add $window 2)) }}
{{ $.Scratch.Set "show" (seq (add (sub $total $size) 3) $total) }}
{{ else }}
{{ $.Scratch.Set "show" (seq (sub $cur $window) (add $cur $window)) }}
{{ end }}
{{ $.Scratch.Add "show" 1 }}
{{ $.Scratch.Add "show" $total }}
{{ else }}
{{ $.Scratch.Set "show" (seq 1 $total) }}
{{ end }}
{{ if .Paginator.HasPrev }}
<a class="prev" href="{{ if .Paginator.HasPrev }}{{ .Paginator.Prev.URL }}{{ else }}#{{ end }}">« Prev</a>
{{ else }}
<p class="prev">« Prev</p>
{{ end }}
<ul class="pages">
{{ range $pag.Pagers }}
{{ $cur := .PageNumber }}
{{ if in ($.Scratch.Get "show") $cur }}
<a href="{{ .URL }}"
{{ if eq . $pag }}class="active"{{ end }}>{{ .PageNumber }}</a>
{{ else if in (slice 2 (sub $total 1)) $cur }}
<a class="disabled">&hellip;</a>
{{ end }}
{{ end }}
</ul>
{{ if .Paginator.HasNext }}
<a class="next" href="{{ if .Paginator.HasNext }}{{ .Paginator.Next.URL }}{{ else }}#{{ end }}">Next »</a>
{{ else }}
<p class="next">Next
{{ end }}
{{ end }}
</nav>
</main>
Expand Down
4 changes: 3 additions & 1 deletion themes/bean/layouts/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ <h2>{{ .Title }}</h2>
<div class="flex-push"></div>
<div>
<a href="{{ .RelPermalink }}">
<h3>More {{ .Title }} > </h3>
{{ $total := len .Pages }}
{{ $total := sub $total 6 }}
<h3>{{ $total }} more {{ .Title }} > </h3>
</a>
</div>
</div>
Expand Down
3 changes: 0 additions & 3 deletions themes/bean/layouts/partials/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ <h3>{{ $title }} | {{ .Site.Title }}</h3>
{{ $text }}
</a>
{{ end }}
{{range ($.Site.GetPage "taxonomyTerm" "categories").Pages }}
<a href="{{ .Permalink }}">{{ .Title }}</a>
{{ end }}
</span>
<span>
<a href="/about">About</a>
Expand Down

0 comments on commit 424acf9

Please sign in to comment.