From 712be2e2a7c08266cbbd7d0b21352b11b36e30f3 Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Fri, 20 Oct 2023 09:39:38 +0200 Subject: [PATCH] feat: add next-prev navigation for filetree menu (#723) --- exampleSite/content/en/usage/configuration.md | 6 +- layouts/_default/baseof.html | 9 +- ...menu-nextprev.html => menu-bundle-np.html} | 57 +++++----- layouts/partials/menu-filetree-np.html | 107 ++++++++++++++++++ 4 files changed, 144 insertions(+), 35 deletions(-) rename layouts/partials/{menu-nextprev.html => menu-bundle-np.html} (57%) create mode 100644 layouts/partials/menu-filetree-np.html diff --git a/exampleSite/content/en/usage/configuration.md b/exampleSite/content/en/usage/configuration.md index 4bfc570..52a85ce 100644 --- a/exampleSite/content/en/usage/configuration.md +++ b/exampleSite/content/en/usage/configuration.md @@ -53,8 +53,7 @@ enableRobotsTXT = true # per page if enabled. Can be enabled per page via 'geekdocCollapseSection'. geekdocCollapseAllSections = true - # (Optional, default true) Show page navigation links at the bottom of each - # docs page (bundle menu only). + # (Optional, default true) Show page navigation links at the bottom of each docs page. geekdocNextPrev = false # (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'. geekdocCollapseAllSections: true - # (Optional, default true) Show page navigation links at the bottom of each - # docs page (bundle menu only). + # (Optional, default true) Show page navigation links at the bottom of each docs page. geekdocNextPrev: false # (Optional, default true) Show a breadcrumb navigation bar at the top of each docs page. diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index ebc39cf..bd3b9d0 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -46,9 +46,16 @@ {{ template "main" . }} + {{ $showPrevNext := (default true .Site.Params.geekdocNextPrev) }} + {{ if $showPrevNext }} + {{ end }} diff --git a/layouts/partials/menu-nextprev.html b/layouts/partials/menu-bundle-np.html similarity index 57% rename from layouts/partials/menu-nextprev.html rename to layouts/partials/menu-bundle-np.html index 6126f95..593b649 100644 --- a/layouts/partials/menu-nextprev.html +++ b/layouts/partials/menu-bundle-np.html @@ -6,9 +6,9 @@ {{ $current.Scratch.Set "nextPage" 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 }} {{ $site := .site }} @@ -44,35 +44,32 @@ {{ $sub := default false .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 }} -{{ $showPrevNext := (and (default true .Site.Params.geekdocNextPrev) .Site.Params.geekdocMenuBundle) }} -{{ if $showPrevNext }} - - {{ with ($current.Scratch.Get "prevPage") }} - - gdoc_arrow_left_alt - {{ .name }} - - {{ end }} - - - {{ with ($current.Scratch.Get "nextPage") }} - - {{ .name }} - gdoc_arrow_right_alt - - {{ end }} - -{{ end }} + + {{ with ($current.Scratch.Get "prevPage") }} + + gdoc_arrow_left_alt + {{ .name }} + + {{ end }} + + + {{ with ($current.Scratch.Get "nextPage") }} + + {{ .name }} + gdoc_arrow_right_alt + + {{ end }} + diff --git a/layouts/partials/menu-filetree-np.html b/layouts/partials/menu-filetree-np.html new file mode 100644 index 0000000..972a5f0 --- /dev/null +++ b/layouts/partials/menu-filetree-np.html @@ -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 }} + + + {{ with ($current.Scratch.Get "prevPage") }} + + gdoc_arrow_left_alt + {{ .name }} + + {{ end }} + + + {{ with ($current.Scratch.Get "nextPage") }} + + {{ .name }} + gdoc_arrow_right_alt + + {{ end }} +