From 17179c683a3eda6a1c89fcb5de4614a85c28e463 Mon Sep 17 00:00:00 2001 From: Joel Pettersson Date: Sun, 14 Aug 2022 13:12:35 -0700 Subject: Fix home page not marked as active in menu Previously, with a menu item as follows, the "Home" link did not get the `active` CSS class and was thus not styled as such. ```toml [[menu.main]] name = "Home" url = "/" weight = 1 ``` The approach used here to determine whether the current page corresponds to a certain menu entry was inspired by the one suggested at https://stackoverflow.com/a/56454338. It is supposedly also more robust when dealing with multilingual sites. --- layouts/partials/footer-menu.html | 2 +- layouts/partials/main-menu-mobile.html | 4 +++- layouts/partials/main-menu.html | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/layouts/partials/footer-menu.html b/layouts/partials/footer-menu.html index 6ec4094..b2a2817 100644 --- a/layouts/partials/footer-menu.html +++ b/layouts/partials/footer-menu.html @@ -3,7 +3,7 @@ {{ $currentPage := . }} {{ range .Site.Menus.footer }} {{ $active := or ($currentPage.IsMenuCurrent "footer" .) ($currentPage.HasMenuCurrent "footer" .) }} - {{ $active = or $active (eq .Name $currentPage.Title) }} + {{ $active = or $active (eq (.URL | relLangURL) ($currentPage.RelPermalink | relLangURL)) }}