diff options
| author | Aditya Telange <21258296+adityatelange@users.noreply.github.com> | 2020-09-20 19:03:43 +0530 |
|---|---|---|
| committer | Aditya Telange <21258296+adityatelange@users.noreply.github.com> | 2020-09-20 19:03:43 +0530 |
| commit | 6770e5e552bc367181f3786169e614683fadeb16 (patch) | |
| tree | 17d5998ae1bde83971ab6cc18964641ed7d36cbc | |
| parent | 46a092553ad84160446baa5557b68ab6f7cf4c59 (diff) | |
menu : add menu location indicator
credits for fix with [.IsMenuCurrent](https://gohugo.io/functions/ismenucurrent/): https://stackoverflow.com/a/56454338
| -rw-r--r-- | assets/css/header.css | 5 | ||||
| -rw-r--r-- | layouts/_default/baseof.html | 2 | ||||
| -rw-r--r-- | layouts/partials/header.html | 11 |
3 files changed, 14 insertions, 4 deletions
diff --git a/assets/css/header.css b/assets/css/header.css index 0263bd3..e12814d 100644 --- a/assets/css/header.css +++ b/assets/css/header.css @@ -38,4 +38,9 @@ .menu a { font-size: 16px; +} + +.menu .active { + font-weight: 500; + border-bottom: 2px solid currentColor; }
\ No newline at end of file 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 |
