diff options
author | Miguel Ángel Moreno <mail@migalmoreno.com> | 2023-09-17 21:32:55 +0200 |
---|---|---|
committer | Miguel Ángel Moreno <mail@migalmoreno.com> | 2023-09-17 21:32:55 +0200 |
commit | e09f17dc9fcc660836687409daf0c542c9d8c1de (patch) | |
tree | 73f3a2599a8f9a328c8a0003f3dbec1f6f5ffaea | |
parent | 88161a4314a183058d9d61445330803b3e66ae65 (diff) |
fix: amend current route highlighting
-rw-r--r-- | assets/js/main.js | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/assets/js/main.js b/assets/js/main.js index d4c8af3..1106b83 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -1,11 +1,12 @@ -function setCopyrightYear() { +const setCopyrightYear = () => { document.querySelector(".footer__year").innerHTML = new Date().getFullYear() } -function highlightCurrentRoute() { - const rx = /\/+$/ +const highlightCurrentRoute = () => { + const routePath = window.location.pathname.split("/").join("") for (let el of document.querySelectorAll(".menu-item__link")) { - if (el.href.replace(rx, "") === window.location.href.replace(rx, "")) { + const linkPath = el.pathname.split("/").join("") + if (linkPath === routePath || linkPath && routePath.includes(linkPath)) { el.classList.add("menu-item__link--selected") } } |