fix(header.liquid): set header link active state properly

This commit is contained in:
Cory Dransfeldt 2025-06-16 06:08:44 -07:00
parent d13984f114
commit 0c64cdf570
No known key found for this signature in database
4 changed files with 15 additions and 6 deletions

View file

@ -1,4 +1,12 @@
const normalizeUrl = (url) =>
url.replace(/index\.php$|index\.html$/i, '').replace(/\.php$|\.html$/i, '') || '/';
export default {
isLinkActive: (category, page) =>
page.includes(category) && page.split('/').filter((a) => a !== '').length <= 1
isLinkActive: (category, page) => {
const normalized = normalizeUrl(page);
return (
normalized.includes(category) && normalized.split('/').filter((a) => a !== '').length <= 1
);
},
normalizeUrl
};

4
package-lock.json generated
View file

@ -1,12 +1,12 @@
{
"name": "coryd.dev",
"version": "10.6.4",
"version": "10.6.5",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "coryd.dev",
"version": "10.6.4",
"version": "10.6.5",
"license": "MIT",
"dependencies": {
"minisearch": "^7.1.2",

View file

@ -1,6 +1,6 @@
{
"name": "coryd.dev",
"version": "10.6.4",
"version": "10.6.5",
"description": "The source for my personal site. Built using 11ty (and other tools).",
"type": "module",
"engines": {

View file

@ -1,3 +1,4 @@
{%- assign normalizedUrl = page.url | normalizeUrl -%}
{%- capture headerContent -%}
<img
srcset="
@ -14,7 +15,7 @@
{%- endcapture -%}
<section class="main-title">
<h1>
{%- if page.url == "/" -%}
{%- if normalizedUrl == "/" -%}
{{ headerContent }}
{%- else -%}
<a href="/" tabindex="0">{{ headerContent }}</a>