From 85ebc72aee8ed03fa9bed91540bf9dfaca7edc13 Mon Sep 17 00:00:00 2001 From: ROOMrepair Date: Thu, 31 Oct 2024 18:15:27 +0800 Subject: [PATCH] fix: try to fix docs pagination bugs Signed-off-by: ROOMrepair --- layouts/docs/second.html | 24 +------ layouts/docs/single.html | 24 +------ layouts/partials/findFirstInNextSection.html | 9 +++ layouts/partials/findLastInPreSection.html | 18 +++++ layouts/partials/page_navigation.html | 71 ++++++++++++++++++++ layouts/partials/pagination.html | 33 +++++++++ 6 files changed, 137 insertions(+), 42 deletions(-) create mode 100644 layouts/partials/findFirstInNextSection.html create mode 100644 layouts/partials/findLastInPreSection.html create mode 100644 layouts/partials/page_navigation.html create mode 100644 layouts/partials/pagination.html diff --git a/layouts/docs/second.html b/layouts/docs/second.html index 0ca39d01a..834b23839 100644 --- a/layouts/docs/second.html +++ b/layouts/docs/second.html @@ -146,29 +146,11 @@ height="0" width="0" style="display:none;visibility:hidden"> {{ end }} + {{ if .IsPage }} - -
- {{ with .Next }} - - - {{ i18n - {{ i18n "Previous" }} - : {{.LinkTitle}} - - - {{ end }} - {{ with .Prev }} - - - - {{ end }} -
+ {{ partial "pagination" . }} {{ end }} +
{{ if .IsPage }} diff --git a/layouts/docs/single.html b/layouts/docs/single.html index e974bcdf6..dfd1e5a01 100644 --- a/layouts/docs/single.html +++ b/layouts/docs/single.html @@ -154,29 +154,11 @@

{{ i18n "Msg-Thank" }}

- {{ if .IsPage }} -
- {{ with .Next }} - - - {{ i18n - {{ i18n "Previous" }} - : {{.LinkTitle}} - - - {{ end }} - {{ with .Prev }} - - - - {{ end }} -
+ {{ if .IsPage }} + {{ partial "pagination" . }} {{ end }} +
{{ if .IsPage }} diff --git a/layouts/partials/findFirstInNextSection.html b/layouts/partials/findFirstInNextSection.html new file mode 100644 index 000000000..26834e793 --- /dev/null +++ b/layouts/partials/findFirstInNextSection.html @@ -0,0 +1,9 @@ +{{ if ne .Parent.CurrentSection .Parent.FirstSection }} +{{ with .}} + +{{ end }} +{{ end }} \ No newline at end of file diff --git a/layouts/partials/findLastInPreSection.html b/layouts/partials/findLastInPreSection.html new file mode 100644 index 000000000..9192d5021 --- /dev/null +++ b/layouts/partials/findLastInPreSection.html @@ -0,0 +1,18 @@ + +{{ if ne .Parent.CurrentSection .Parent.FirstSection }} + +{{ if .IsSection}} +{{ $curSection := .Pages.ByWeight }} +{{ $l := len $curSection}} +{{ $page := index $curSection (sub $l 1)}} +{{ partial "findLastInPreSection" $page}} +{{ else }} + + + {{ i18n + {{ i18n "Previous" }} + : {{.LinkTitle}} + +{{ end }} + +{{ end }} \ No newline at end of file diff --git a/layouts/partials/page_navigation.html b/layouts/partials/page_navigation.html new file mode 100644 index 000000000..f3b1e5760 --- /dev/null +++ b/layouts/partials/page_navigation.html @@ -0,0 +1,71 @@ +{{ $current := .context }} + + + +{{ $g_parent := "" }} +{{ if $current.IsPage }} +{{ $g_parent = $current.Parent.Parent }} +{{ else }} +{{ $g_parent = $current.Parent}} +{{ end }} + + + +{{ $p_section := $g_parent.Pages.ByWeight }} +{{ $length := len $p_section }} + +{{ if .prev }} +{{ $first := index $p_section 0}} + + + +{{ if $current.InSection $first.CurrentSection }} + +{{ partial "page_navigation" (dict "context" $g_parent "prev" true)}} + + +{{else}} + + +{{ $curIndex := 0 }} +{{ range $i, $p_sec := $p_section}} +{{ if eq $p_sec $current.CurrentSection}} +{{ $curIndex = $i }} +{{ end }} +{{ end }} + +{{ $prevPage := index $p_section (sub $curIndex 1) }} +{{ partial "findLastInPreSection" $prevPage}} + +{{ end }} + + + +{{ else }} + + +{{ $last := index $p_section (sub $length 1)}} + + +{{ if $current.InSection $last.CurrentSection }} + + +{{ partial "page_navigation" (dict "context" $g_parent "prev" false)}} + + +{{ else }} + +{{ $curIndex := 0 }} +{{ range $i, $p_sec := $p_section}} +{{ if eq $p_sec $current.CurrentSection}} +{{ $curIndex = $i }} +{{ end }} +{{ end }} + +{{ $nextPage := index $p_section (add $curIndex 1) }} +{{ partial "findFirstInNextSection" $nextPage}} + +{{ end }} + + +{{ end }} \ No newline at end of file diff --git a/layouts/partials/pagination.html b/layouts/partials/pagination.html new file mode 100644 index 000000000..6fe3074bd --- /dev/null +++ b/layouts/partials/pagination.html @@ -0,0 +1,33 @@ +
+ + + {{ $current := .}} + {{ $p := .Parent.Pages.ByWeight }} + {{ $length := len $p }} + + + {{ $curIndex := 0 }} + {{ range $i, $p_sec := $p}} + + {{ if eq $p_sec $current}} + {{ $curIndex = $i }} + {{ end }} + {{ end }} + + + {{ if gt $curIndex 0}} + {{ $prevPage := index $p (sub $curIndex 1) }} + {{ partial "findLastInPreSection" $prevPage}} + {{ else }} + {{ partial "page_navigation" (dict "context" . "prev" true)}} + {{ end }} + + + {{ if lt $curIndex (sub $length 1) }} + {{ $nextPage := index $p (add $curIndex 1)}} + {{ partial "findFirstInNextSection" $nextPage}} + {{ else }} + {{ partial "page_navigation" (dict "context" . "prev" false)}} + {{ end }} + +
\ No newline at end of file