From ec84fecdc0ce23942b603e6e63bb91ac224f14fd Mon Sep 17 00:00:00 2001 From: hossainemruz Date: Sun, 6 Jun 2021 21:41:32 +0600 Subject: [PATCH] Fix Prev/Next navigator was not pointing to the actual prev/next article Signed-off-by: hossainemruz --- layouts/partials/helpers/get-pages.html | 10 +++ .../navigators/next-prev-navigator.html | 62 ++++++++++--------- 2 files changed, 44 insertions(+), 28 deletions(-) create mode 100644 layouts/partials/helpers/get-pages.html diff --git a/layouts/partials/helpers/get-pages.html b/layouts/partials/helpers/get-pages.html new file mode 100644 index 000000000..8e06483a7 --- /dev/null +++ b/layouts/partials/helpers/get-pages.html @@ -0,0 +1,10 @@ +{{ $pages:= slice}} +{{ range . }} + {{ if .HasChildren }} + {{ $nestedPages:=partial "helpers/get-pages.html" .Children }} + {{ $pages = $pages | append $nestedPages }} + {{ else }} + {{ $pages = $pages | append .Page }} + {{ end }} +{{ end }} +{{ return $pages}} diff --git a/layouts/partials/navigators/next-prev-navigator.html b/layouts/partials/navigators/next-prev-navigator.html index f87c369c7..3738c677c 100644 --- a/layouts/partials/navigators/next-prev-navigator.html +++ b/layouts/partials/navigators/next-prev-navigator.html @@ -1,33 +1,39 @@ +{{ $curPage := . }} +{{ $prevPage := "" }} +{{ $nextPage := "" }} + + +{{ $pages := partial "helpers/get-pages.html" site.Menus.sidebar }} + + +{{ $idx := 0 }} +{{ range $pages }} + {{ if eq .RelPermalink $curPage.RelPermalink }} + {{ $prevPage = index $pages (sub $idx 1) }} + {{ $nextPage = index $pages (add $idx 1) }} + {{ end }} + {{ $idx = add $idx 1 }} +{{ end }} +
-{{ $currentPage := . }} -{{ range (where site.RegularPages.ByDate "Type" "in" site.Params.mainSections )}} - {{ if eq .RelPermalink $currentPage.RelPermalink }} - {{ if .Next }} - {{ if (in site.Params.mainSections .Next.Type) }} -