diff --git a/exampleSite/hugo.yaml b/exampleSite/hugo.yaml index 25a3d5b..6d884ef 100644 --- a/exampleSite/hugo.yaml +++ b/exampleSite/hugo.yaml @@ -170,6 +170,8 @@ params: # date | lastmod | publishDate | title | weight sortBy: date sortOrder: desc # or "asc" + # Pagination + pagerSize: 20 article: displayPagination: true diff --git a/exampleSite/hugo_stats.json b/exampleSite/hugo_stats.json index 438d2cf..4f3944d 100644 --- a/exampleSite/hugo_stats.json +++ b/exampleSite/hugo_stats.json @@ -440,6 +440,7 @@ "hx:max-w-[min(calc(100vw-2rem),calc(100%+20rem))]", "hx:max-w-none", "hx:max-xl:hidden", + "hx:mb-1", "hx:mb-10", "hx:mb-12", "hx:mb-16", diff --git a/i18n/en.yaml b/i18n/en.yaml index cd9115c..2ff6b7c 100644 --- a/i18n/en.yaml +++ b/i18n/en.yaml @@ -13,3 +13,5 @@ tags: "Tags" poweredBy: "Powered by Hextra" readMore: "Read more →" searchPlaceholder: "Search..." +previous: "Prev" +next: "Next" diff --git a/i18n/fa.yaml b/i18n/fa.yaml index 9264a08..7747e6c 100644 --- a/i18n/fa.yaml +++ b/i18n/fa.yaml @@ -13,3 +13,5 @@ tags: "برچسب‌ها" poweredBy: "طراحی شده توسط هگزترا" readMore: "ادامه مطلب ←" searchPlaceholder: "جستجو..." +previous: "قبلی" +next: "بعدی" diff --git a/i18n/ja.yaml b/i18n/ja.yaml index 6f86af4..360ef59 100644 --- a/i18n/ja.yaml +++ b/i18n/ja.yaml @@ -12,3 +12,5 @@ tags: "タグ" poweredBy: "提供元 Hextra" readMore: "もっと読む →" searchPlaceholder: "検索..." +previous: "前へ" +next: "次へ" diff --git a/i18n/zh-cn.yaml b/i18n/zh-cn.yaml index cc7f64e..9d929fd 100644 --- a/i18n/zh-cn.yaml +++ b/i18n/zh-cn.yaml @@ -12,3 +12,5 @@ tags: "标签" poweredBy: "由 Hextra 驱动" readMore: "更多 →" searchPlaceholder: "搜索文档..." +previous: "上一页" +next: "下一页" diff --git a/layouts/_partials/components/blog-pager.html b/layouts/_partials/components/blog-pager.html new file mode 100644 index 0000000..1b6b130 --- /dev/null +++ b/layouts/_partials/components/blog-pager.html @@ -0,0 +1,39 @@ +{{/* + Blog pagination component for list pages (e.g., blog list, category list) + + Usage: {{ partial "components/blog-pager.html" $paginator }} + + Parameters: + - . (context): Hugo paginator object +*/}} + +{{- $paginator := . -}} +{{- $prevText := (T "previous") | default "Prev" -}} +{{- $nextText := (T "next") | default "Next" -}} +{{- $prevLabel := printf "%s %d/%d" $prevText (sub $paginator.PageNumber 1) $paginator.TotalPages -}} +{{- $nextLabel := printf "%s %d/%d" $nextText (add $paginator.PageNumber 1) $paginator.TotalPages -}} + +{{- if or $paginator.HasPrev $paginator.HasNext -}} +
+ {{- if $paginator.HasPrev -}} + + {{- partial "utils/icon.html" (dict "name" "chevron-right" "attributes" "class=\"hx:inline hx:h-5 hx:shrink-0 hx:ltr:rotate-180\"") -}} + {{ $prevLabel }} + + {{- end -}} + {{- if $paginator.HasNext -}} + + {{ $nextLabel }} + {{- partial "utils/icon.html" (dict "name" "chevron-right" "attributes" "class=\"hx:inline hx:h-5 hx:shrink-0 hx:rtl:-rotate-180\"") -}} + + {{- end -}} +
+{{- end -}} \ No newline at end of file diff --git a/layouts/blog/list.html b/layouts/blog/list.html index 5527ba8..78d6afc 100644 --- a/layouts/blog/list.html +++ b/layouts/blog/list.html @@ -8,7 +8,9 @@ {{ if .Title }}

{{ .Title }}

{{ end }}
{{ .Content }}
{{- $pages := partial "utils/sort-pages" (dict "page" . "by" site.Params.blog.list.sortBy "order" site.Params.blog.list.sortOrder) -}} - {{- range $pages }} + {{- $pagerSize := site.Params.blog.list.pagerSize | default 10 -}} + {{- $paginator := .Paginate $pages $pagerSize -}} + {{- range $paginator.Pages }}

{{ .Title }}

{{ if site.Params.blog.list.displayTags }} @@ -23,6 +25,10 @@

{{ partial "utils/format-date" .Date }}

{{ end -}} + + {{- if gt $paginator.TotalPages 1 -}} + {{ partial "components/blog-pager.html" $paginator }} + {{- end -}}