feat: add next-prev navigation for filetree menu (#723)

This commit is contained in:
Robert Kaussow 2023-10-20 09:39:38 +02:00 committed by GitHub
parent 21d310b884
commit 712be2e2a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 144 additions and 35 deletions

View File

@ -53,8 +53,7 @@ enableRobotsTXT = true
# per page if enabled. Can be enabled per page via 'geekdocCollapseSection'. # per page if enabled. Can be enabled per page via 'geekdocCollapseSection'.
geekdocCollapseAllSections = true geekdocCollapseAllSections = true
# (Optional, default true) Show page navigation links at the bottom of each # (Optional, default true) Show page navigation links at the bottom of each docs page.
# docs page (bundle menu only).
geekdocNextPrev = false geekdocNextPrev = false
# (Optional, default true) Show a breadcrumb navigation bar at the top of each docs page. # (Optional, default true) Show a breadcrumb navigation bar at the top of each docs page.
@ -179,8 +178,7 @@ params:
# per page if enabled. Can be enabled per page via 'geekdocCollapseSection'. # per page if enabled. Can be enabled per page via 'geekdocCollapseSection'.
geekdocCollapseAllSections: true geekdocCollapseAllSections: true
# (Optional, default true) Show page navigation links at the bottom of each # (Optional, default true) Show page navigation links at the bottom of each docs page.
# docs page (bundle menu only).
geekdocNextPrev: false geekdocNextPrev: false
# (Optional, default true) Show a breadcrumb navigation bar at the top of each docs page. # (Optional, default true) Show a breadcrumb navigation bar at the top of each docs page.

View File

@ -46,9 +46,16 @@
{{ template "main" . }} {{ template "main" . }}
{{ $showPrevNext := (default true .Site.Params.geekdocNextPrev) }}
{{ if $showPrevNext }}
<div class="gdoc-page__footer flex flex-wrap justify-between"> <div class="gdoc-page__footer flex flex-wrap justify-between">
{{ partial "menu-nextprev" . }} {{ if .Site.Params.geekdocMenuBundle }}
{{ partial "menu-bundle-np" . }}
{{ else }}
{{ partial "menu-filetree-np" . }}
{{ end }}
</div> </div>
{{ end }}
</div> </div>
</main> </main>

View File

@ -6,9 +6,9 @@
{{ $current.Scratch.Set "nextPage" false }} {{ $current.Scratch.Set "nextPage" false }}
{{ $current.Scratch.Set "prevPage" false }} {{ $current.Scratch.Set "prevPage" false }}
{{ template "menu_nextprev" dict "sect" $.Site.Data.menu.main.main "current" $current "site" $site }} {{ template "menu-bundle-np" dict "sect" $.Site.Data.menu.main.main "current" $current "site" $site }}
{{ define "menu_nextprev" }} {{ define "menu-bundle-np" }}
{{ $current := .current }} {{ $current := .current }}
{{ $site := .site }} {{ $site := .site }}
@ -44,14 +44,12 @@
{{ $sub := default false .sub }} {{ $sub := default false .sub }}
{{ if $sub }} {{ if $sub }}
{{ template "menu_nextprev" dict "sect" $sub "current" ($current.Scratch.Get "current") "site" ($current.Scratch.Get "site") }} {{ template "menu-bundle-np" dict "sect" $sub "current" ($current.Scratch.Get "current") "site" ($current.Scratch.Get "site") }}
{{ end }} {{ end }}
{{ end }} {{ end }}
{{ end }} {{ end }}
{{ $showPrevNext := (and (default true .Site.Params.geekdocNextPrev) .Site.Params.geekdocMenuBundle) }} <span class="gdoc-page__nav">
{{ if $showPrevNext }}
<span class="gdoc-page__nav">
{{ with ($current.Scratch.Get "prevPage") }} {{ with ($current.Scratch.Get "prevPage") }}
<a <a
class="gdoc-page__nav--prev flex align-center" class="gdoc-page__nav--prev flex align-center"
@ -62,8 +60,8 @@
{{ .name }} {{ .name }}
</a> </a>
{{ end }} {{ end }}
</span> </span>
<span class="gdoc-page__nav"> <span class="gdoc-page__nav">
{{ with ($current.Scratch.Get "nextPage") }} {{ with ($current.Scratch.Get "nextPage") }}
<a <a
class="gdoc-page__nav--next flex align-center" class="gdoc-page__nav--next flex align-center"
@ -74,5 +72,4 @@
<i class="gdoc-icon">gdoc_arrow_right_alt</i> <i class="gdoc-icon">gdoc_arrow_right_alt</i>
</a> </a>
{{ end }} {{ end }}
</span> </span>
{{ end }}

View File

@ -0,0 +1,107 @@
{{ $current := . }}
{{ $site := .Site }}
{{ $current.Scratch.Set "prev" false }}
{{ $current.Scratch.Set "getNext" false }}
{{ $current.Scratch.Set "nextPage" false }}
{{ $current.Scratch.Set "prevPage" false }}
{{ template "menu-filetree-np" dict "sect" .Site.Home.Sections "current" $current "site" $site }}
{{ define "menu-filetree-np" }}
{{ $current := .current }}
{{ $site := .site }}
{{ $sortBy := (default "title" .current.Site.Params.geekdocFileTreeSortBy | lower) }}
{{ range .sect.GroupBy "Weight" }}
{{ $rangeBy := .ByTitle }}
{{ if eq $sortBy "title" }}
{{ $rangeBy = .ByTitle }}
{{ else if eq $sortBy "linktitle" }}
{{ $rangeBy = .ByLinkTitle }}
{{ else if eq $sortBy "date" }}
{{ $rangeBy = .ByDate }}
{{ else if eq $sortBy "publishdate" }}
{{ $rangeBy = .ByPublishDate }}
{{ else if eq $sortBy "expirydate" }}
{{ $rangeBy = .ByExpiryDate }}
{{ else if eq $sortBy "lastmod" }}
{{ $rangeBy = .ByLastmod }}
{{ else if eq $sortBy "title_reverse" }}
{{ $rangeBy = .ByTitle.Reverse }}
{{ else if eq $sortBy "linktitle_reverse" }}
{{ $rangeBy = .ByLinkTitle.Reverse }}
{{ else if eq $sortBy "date_reverse" }}
{{ $rangeBy = .ByDate.Reverse }}
{{ else if eq $sortBy "publishdate_reverse" }}
{{ $rangeBy = .ByPublishDate.Reverse }}
{{ else if eq $sortBy "expirydate_reverse" }}
{{ $rangeBy = .ByExpiryDate.Reverse }}
{{ else if eq $sortBy "lastmod_reverse" }}
{{ $rangeBy = .ByLastmod.Reverse }}
{{ end }}
{{ range $rangeBy }}
{{ $current.Scratch.Set "current" $current }}
{{ $current.Scratch.Set "site" $site }}
{{ if not .Params.geekdocHidden }}
{{ $numberOfPages := (add (len .Pages) (len .Sections)) }}
{{ $site := $current.Scratch.Get "site" }}
{{ $this := . }}
{{ $current := $current.Scratch.Get "current" }}
{{ $current.Scratch.Set "refName" (partial "utils/title" .) }}
{{ $name := $current.Scratch.Get "refName" }}
{{ if $current.Scratch.Get "getNext" }}
{{ if $this.Content }}
{{ $current.Scratch.Set "nextPage" (dict "name" $name "this" $this) }}
{{ $current.Scratch.Set "getNext" false }}
{{ end }}
{{ end }}
{{ if eq $current.RelPermalink $this.RelPermalink }}
{{ $current.Scratch.Set "prevPage" ($current.Scratch.Get "prev") }}
{{ $current.Scratch.Set "getNext" true }}
{{ end }}
{{ if $this.Content }}
{{ $current.Scratch.Set "prev" (dict "name" $name "this" $this) }}
{{ end }}
{{ $sub := and (ne $numberOfPages 0) (not .Params.geekdocFlatSection) }}
{{ if $sub }}
{{ template "menu-filetree-np" dict "sect" .Pages "current" $current }}
{{ end }}
{{ end }}
{{ end }}
{{ end }}
{{ end }}
<span class="gdoc-page__nav">
{{ with ($current.Scratch.Get "prevPage") }}
<a
class="gdoc-page__nav--prev flex align-center"
href="{{ .this.RelPermalink }}"
title="{{ .name }}"
>
<i class="gdoc-icon">gdoc_arrow_left_alt</i>
{{ .name }}
</a>
{{ end }}
</span>
<span class="gdoc-page__nav">
{{ with ($current.Scratch.Get "nextPage") }}
<a
class="gdoc-page__nav--next flex align-center"
href="{{ .this.RelPermalink }}"
title="{{ .name }}"
>
{{ .name }}
<i class="gdoc-icon">gdoc_arrow_right_alt</i>
</a>
{{ end }}
</span>