Fix Prev/Next navigator was not pointing to the actual prev/next article (#348)
Signed-off-by: hossainemruz <hossainemruz@gmail.com>
This commit is contained in:
parent
929a78837a
commit
61e5a34171
2 changed files with 44 additions and 28 deletions
10
layouts/partials/helpers/get-pages.html
Normal file
10
layouts/partials/helpers/get-pages.html
Normal file
|
@ -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}}
|
|
@ -1,33 +1,39 @@
|
|||
{{ $curPage := . }}
|
||||
{{ $prevPage := "" }}
|
||||
{{ $nextPage := "" }}
|
||||
|
||||
<!-- List all the pages. It uses the sidebar menu to discover the page order. -->
|
||||
{{ $pages := partial "helpers/get-pages.html" site.Menus.sidebar }}
|
||||
|
||||
<!-- Now, find the current page index in the pages list. Then, find previous page and next page. -->
|
||||
{{ $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 }}
|
||||
|
||||
<div class="row next-prev-navigator">
|
||||
{{ $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) }}
|
||||
{{ if $prevPage }}
|
||||
<div class="col-md-6 previous-article">
|
||||
<a href="{{.Next.RelPermalink}}" title="{{ .Next.Title }}" class="btn btn-outline-info">
|
||||
<a href="{{ $prevPage.RelPermalink }}" title="{{ $prevPage.Title }}" class="btn btn-outline-info">
|
||||
<div><i class="fas fa-chevron-circle-left"></i> {{ i18n "prev" }}</div>
|
||||
<div class="next-prev-text">{{ .Next.Title }}</div>
|
||||
<div class="next-prev-text">{{ $prevPage.Title }}</div>
|
||||
</a>
|
||||
</div>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ if .Prev }}
|
||||
{{ if (in site.Params.mainSections .Prev.Type) }}
|
||||
{{ if $nextPage }}
|
||||
{{ $columnWidth:="col-md-12" }}
|
||||
{{ if .Next }}
|
||||
{{ if (in site.Params.mainSections .Next.Type) }}
|
||||
{{ if $prevPage }}
|
||||
{{ $columnWidth = "col-md-6" }}
|
||||
{{ end}}
|
||||
{{ end}}
|
||||
<div class="{{ $columnWidth }} next-article">
|
||||
<a href="{{ .Prev.RelPermalink }}" title="{{ .Prev.Title }}" class="btn btn-outline-info">
|
||||
<a href="{{ $nextPage.RelPermalink }}" title="{{ $nextPage.Title }}" class="btn btn-outline-info">
|
||||
<div>{{ i18n "next" }} <i class="fas fa-chevron-circle-right"></i></div>
|
||||
<div class="next-prev-text">{{ .Prev.Title }}</div>
|
||||
<div class="next-prev-text">{{ $nextPage.Title }}</div>
|
||||
</a>
|
||||
</div>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
</div>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue