diff options
author | mms <michal@sapka.me> | 2024-04-24 20:00:47 +0200 |
---|---|---|
committer | mms <michal@sapka.me> | 2024-04-24 20:00:47 +0200 |
commit | 06a78ff287d3fc51cb8f5d04dfdc751379fa10ff (patch) | |
tree | 926326f1dd7243405114af72eb65bd72f4446ca2 /layouts | |
parent | 1c29765a2b4cb5d2702d2476cdc8985a6870d541 (diff) |
chore: add bottom nav to BSD
Diffstat (limited to 'layouts')
-rw-r--r-- | layouts/_default/list.html | 3 | ||||
-rw-r--r-- | layouts/_default/single.html | 6 | ||||
-rw-r--r-- | layouts/partials/single/bottom_nav.html | 82 |
3 files changed, 89 insertions, 2 deletions
diff --git a/layouts/_default/list.html b/layouts/_default/list.html index a7b0668..f106a52 100644 --- a/layouts/_default/list.html +++ b/layouts/_default/list.html @@ -2,6 +2,9 @@ {{if .Page.Content}} {{ .Page.Content }} +{{- if .Params.primary_menu }} +{{ partial "single/bottom_nav.html" (dict "menuID" .Page.Params.primary_menu "page" .) }} +{{- end }} {{ else }} {{ if in .Page.Params.Categories "blog" }} {{ partial "partials/blog_index.html" . }} diff --git a/layouts/_default/single.html b/layouts/_default/single.html index 1efacb3..0ac881c 100644 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -39,5 +39,7 @@ <a href="{{ .RelPermalink }}">{{ or .Page.Params.shortname .Page.Name }}</a> → {{ end }} {{ end }} -{{ end }} - +{{- if .Params.primary_menu }} +{{ partial "single/bottom_nav.html" (dict "menuID" .Page.Params.primary_menu "page" .) }} +{{- end }} +{{- end }} diff --git a/layouts/partials/single/bottom_nav.html b/layouts/partials/single/bottom_nav.html new file mode 100644 index 0000000..88dbf9c --- /dev/null +++ b/layouts/partials/single/bottom_nav.html @@ -0,0 +1,82 @@ +<hr> +{{- $page := .page }} +{{- $menuID := cast.ToString .menuID }} + +{{- if $menuID }} + {{- with index site.Menus $menuID }} + {{- partial "inline/single/walk.html" (dict "page" $page "menuEntries" . ) }} + {{- end }} +{{- end }} + +{{- partial "inline/single/up.html" (dict "page" $page ) }} + +{{- define "partials/inline/single/walk.html" }} + {{- $page := .page }} + {{- $found := false }} + +<!-- Check if current entries contain current page --> + {{- range .menuEntries }} + {{- if $page.IsMenuCurrent .Menu . }} + {{- $found = . }} + {{- end }} + {{- end }} + +{{ if eq $found false}} +<!-- current page not found, go to next levels --> + {{- range .menuEntries }} + {{- with .Children }} + {{- partial "inline/single/walk.html" (dict "page" $page "menuEntries" . ) }} + {{- end }} + {{- end }} +{{- else }} +<!-- current page found --> + +{{ $found_weight := $found.Weight }} +{{ $found_url := $found.URL }} + +<!-- search for prev page --> +{{- range (where + (where + (where + (where + .menuEntries + "Params.placeholder" "ne" true) + "Params.nonpage" "ne" true) + "URL" "ne" $found_url) +"Weight" "le" $found_weight) | last 1 }} + + Prev: <a href="{{.URL}}">{{ .Name }}</a>, +{{- end }} + +<!-- search for next page --> +{{- range (where + (where + (where + (where + .menuEntries + "Params.placeholder" "ne" true) + "Params.nonpage" "ne" true) + "URL" "ne" $found_url) +"Weight" "gt" $found_weight) | first 1 }} + Next: <a href="{{.URL}}">{{ .Name }}</a>, +{{- end }} + +{{- end }} + +{{- end }} + +{{- define "partials/inline/single/up.html" }} + {{- $page := .page }} + {{- $nearest := true }} + Up: + {{- range $page.Ancestors }} + {{- if .LinkTitle}} + {{- if $nearest}} + <a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a> + {{- $nearest = false }} + {{- else}} + [<a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a>] + {{- end }} + {{- end }} + {{- end }} +{{- end }} |