fix(header.liquid): set header link active state properly
This commit is contained in:
parent
d13984f114
commit
0c64cdf570
4 changed files with 15 additions and 6 deletions
|
@ -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
4
package-lock.json
generated
|
@ -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",
|
||||
|
|
|
@ -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": {
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue