Skip to content

Commit

Permalink
🐛 Fix pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
Ice-Hazymoon committed Jun 10, 2022
1 parent a30f353 commit dc150b1
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 46 deletions.
31 changes: 16 additions & 15 deletions layouts/_default/taxonomy.html
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
{{- define "main" -}}
<div class="page-blog relative px-6 md:px-10">
<div>
<div class="article-list mx-auto">
<div class="flex items-center py-6 text-xl">
<i class="eva eva-folder-remove-outline mr-2"></i>
{{- if eq .Data.Plural "tags" -}}
{{- T "taxonomy.tag" (dict "Count" (len .Pages) "Title" .Title) | safeHTML -}}
{{- else -}}
{{- T "taxonomy.category" (dict "Count" (len .Pages) "Title" .Title) | safeHTML -}}
{{- end -}}
</div>
<div>
{{- range .Pages -}}
{{- partial "article-list/article" . -}}
{{- end -}}
</div>
<div class="article-list mx-auto">
<div class="flex items-center py-6 text-xl">
<i class="eva eva-folder-remove-outline mr-2"></i>
{{- if eq .Data.Plural "tags" -}}
{{- T "taxonomy.tag" (dict "Count" (len .Pages) "Title" .Title) | safeHTML -}}
{{- else -}}
{{- T "taxonomy.category" (dict "Count" (len .Pages) "Title" .Title) | safeHTML -}}
{{- end -}}
</div>
<div>
{{- $paginator := .Paginate (where .Pages "Type" "in" (slice "posts" "status")) -}}
{{- range $paginator.Pages -}}
{{- partial "article-list/article" . -}}
{{- end -}}
</div>
</div>

{{- partial "article-list/components/pagination" . -}}
</div>
{{- end -}}
30 changes: 1 addition & 29 deletions layouts/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,6 @@
</div>
</div>

<nav role="navigation" class="pagination bottom-0 left-0 flex w-full items-center justify-between pb-10 text-gray-600 dark:text-darkTextPlaceholder">
<a
href="{{- if .Paginator.HasPrev -}}
{{- .Paginator.Prev.URL -}}
{{- else -}}
/
{{- end -}}"
title="{{- T "page.prev" -}}"
class="{{- if not .Paginator.HasPrev -}}
opacity-0 pointer-events-none
{{- end -}} flex h-10 w-10 cursor-pointer items-center justify-center rounded-full border bg-white text-xl transition duration-300 ease-[ease] hover:border-none hover:bg-theme hover:text-white dark:border-darkBorder dark:bg-darkBgAccent dark:text-darkTextPlaceholder dark:hover:text-darkText"
>
<i class="eva eva-arrow-left-outline"></i>
</a>
<span>- {{ T "page.pagination" (dict "PageNumber" .Paginator.PageNumber "TotalPages" .Paginator.TotalPages) }} -</span>
<a
href="{{- if .Paginator.HasNext -}}
{{- .Paginator.Next.URL -}}
{{- else -}}
/
{{- end -}}"
title="{{- T "page.next" -}}"
class="{{- if not .Paginator.HasNext -}}
opacity-0 pointer-events-none
{{- end -}} flex h-10 w-10 cursor-pointer items-center justify-center rounded-full border bg-white text-xl transition duration-300 ease-[ease] hover:border-none hover:bg-theme hover:text-white dark:border-darkBorder dark:bg-darkBgAccent dark:text-darkTextPlaceholder dark:hover:text-darkText"
>
<i class="eva eva-arrow-right-outline"></i>
</a>
</nav>
{{- partial "article-list/components/pagination" . -}}
</div>
{{- end -}}
29 changes: 29 additions & 0 deletions layouts/partials/article-list/components/pagination.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<nav role="navigation" class="pagination bottom-0 left-0 flex w-full items-center justify-between pb-10 text-gray-600 dark:text-darkTextPlaceholder">
<a
href="{{- if .Paginator.HasPrev -}}
{{- .Paginator.Prev.URL -}}
{{- else -}}
/
{{- end -}}"
title="{{- T "page.prev" -}}"
class="{{- if not .Paginator.HasPrev -}}
opacity-0 pointer-events-none
{{- end -}} flex h-10 w-10 cursor-pointer items-center justify-center rounded-full border bg-white text-xl transition duration-300 ease-[ease] hover:border-none hover:bg-theme hover:text-white dark:border-darkBorder dark:bg-darkBgAccent dark:text-darkTextPlaceholder dark:hover:text-darkText"
>
<i class="eva eva-arrow-left-outline"></i>
</a>
<span>- {{ T "page.pagination" (dict "PageNumber" .Paginator.PageNumber "TotalPages" .Paginator.TotalPages) }} -</span>
<a
href="{{- if .Paginator.HasNext -}}
{{- .Paginator.Next.URL -}}
{{- else -}}
/
{{- end -}}"
title="{{- T "page.next" -}}"
class="{{- if not .Paginator.HasNext -}}
opacity-0 pointer-events-none
{{- end -}} flex h-10 w-10 cursor-pointer items-center justify-center rounded-full border bg-white text-xl transition duration-300 ease-[ease] hover:border-none hover:bg-theme hover:text-white dark:border-darkBorder dark:bg-darkBgAccent dark:text-darkTextPlaceholder dark:hover:text-darkText"
>
<i class="eva eva-arrow-right-outline"></i>
</a>
</nav>
12 changes: 10 additions & 2 deletions layouts/partials/data/title.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,29 @@
{{- if .IsHome -}}
<!-- Homepage, and it's pagination -->

<!-- Build paginator -->
{{ $pages := where site.RegularPages "Type" "in" (slice "posts" "status") }}
{{ $pag := .Paginate $pages }}

{{ if .Paginator.HasPrev }}
<!-- Paginated. Append page number to title -->
{{ $title = printf "%s - %s" (T "page.page" .Paginator.PageNumber) $siteTitle }}
{{ $title = printf "%s - %s" (T "page.page" (string .Paginator.PageNumber)) $siteTitle }}
{{ else }}
{{ $title = $siteTitle}}
{{ end }}
{{- else if eq .Kind "term" -}}
<!-- Taxonomy page -->

<!-- Build paginator -->
{{ $pages := where .Pages "Type" "in" (slice "posts" "status") }}
{{ $pag := .Paginate $pages }}

<!-- {TAXONOMY_TYPE}: {TAXONOMY_TERM} -->
{{ $title = slice (T (printf `taxonomy._%s` .Data.Plural)) ": " $title }}

{{ if .Paginator.HasPrev }}
<!-- Add page number-->
{{ $title = $title | append " - " .Paginator }}
{{ $title = $title | append " - " (T "page.page" (string .Paginator.PageNumber)) }}
{{ end }}

{{ $title = $title | append " - " $siteTitle }}
Expand Down

0 comments on commit dc150b1

Please sign in to comment.