summaryrefslogtreecommitdiff
path: root/layouts
diff options
context:
space:
mode:
authorAditya Telange <21258296+adityatelange@users.noreply.github.com>2020-09-20 19:03:43 +0530
committerAditya Telange <21258296+adityatelange@users.noreply.github.com>2020-09-20 19:03:43 +0530
commit6770e5e552bc367181f3786169e614683fadeb16 (patch)
tree17d5998ae1bde83971ab6cc18964641ed7d36cbc /layouts
parent46a092553ad84160446baa5557b68ab6f7cf4c59 (diff)
menu : add menu location indicator
credits for fix with [.IsMenuCurrent](https://gohugo.io/functions/ismenucurrent/): https://stackoverflow.com/a/56454338
Diffstat (limited to 'layouts')
-rw-r--r--layouts/_default/baseof.html2
-rw-r--r--layouts/partials/header.html11
2 files changed, 9 insertions, 4 deletions
diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html
index c2cb567..7253249 100644
--- a/layouts/_default/baseof.html
+++ b/layouts/_default/baseof.html
@@ -8,7 +8,7 @@
<body
class="{{ if (and (eq .Kind `page` ) (ne .Layout `archives`)) }}single{{ else }}list{{ if .IsHome }} home {{ end }}{{ end }}{{ if eq $.Site.Params.defaultTheme `dark` }} dark {{ end }}"
id="top">
- {{- partialCached "header.html" . }}
+ {{- partialCached "header.html" . .Page}}
<main class="main">
{{- block "main" . }}
{{end }}
diff --git a/layouts/partials/header.html b/layouts/partials/header.html
index 7be916c..6c02c7c 100644
--- a/layouts/partials/header.html
+++ b/layouts/partials/header.html
@@ -12,14 +12,19 @@
{{- else }}
<p class="logo"><a href="{{ "" | absLangURL }}">{{ .Site.Title }}</a></p>
{{- end }}
- {{- if .Site.Menus.main }}
+ {{ $currentPage := . }}
<ul class="menu" id="menu" onscroll="menu_on_scroll()">
{{- range .Site.Menus.main }}
+ {{ $menu_item_url := .URL | relLangURL }}
+ {{ $page_url:= $currentPage.RelPermalink | relLangURL }}
<li>
- <a href="{{ .URL | absLangURL}}">{{ .Name }}</a>
+ <a href="{{ .URL | absLangURL }}">
+ <span {{ if eq $menu_item_url $page_url }}
+ {{/* the menu item links to the current page (with relLangURL) */}} class="active"
+ {{ end }}>{{ .Name }}</span>
+ </a>
</li>
{{- end }}
</ul>
- {{- end }}
</nav>
</header> \ No newline at end of file