From 4c60081298a28fed4d19e0dd6417624640eb34ca Mon Sep 17 00:00:00 2001 From: passthem Date: Wed, 1 Apr 2026 20:20:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=BC=E8=88=AA=E6=A0=8F=E4=B8=8E=E9=A6=96?= =?UTF-8?q?=E9=A1=B5=E5=8A=A8=E7=94=BB=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layout/FullLayoutV1.astro | 41 ++++++++++++++++++++++++++++++++ src/pages/index.astro | 44 +++++++++++++++++++++++++++++++---- 2 files changed, 81 insertions(+), 4 deletions(-) diff --git a/src/layout/FullLayoutV1.astro b/src/layout/FullLayoutV1.astro index 8851f9b..0161ad6 100644 --- a/src/layout/FullLayoutV1.astro +++ b/src/layout/FullLayoutV1.astro @@ -63,6 +63,11 @@ const { title = '小帕的小窝' } = Astro.props navMain?.classList.add('nav-container-hidden') } + const navOpen = () => { + const navMain = document.getElementById('nav-main') + navMain?.classList.remove('nav-container-hidden') + } + document.getElementById('nav-main')?.addEventListener('click', (e) => { const target = e.target as HTMLElement if (target.id == 'nav-main') { @@ -70,6 +75,18 @@ const { title = '小帕的小窝' } = Astro.props } }) + document.getElementById('nav-main')?.addEventListener('focusin', navOpen) + document.getElementById('nav-main')?.addEventListener('focusout', (e) => { + if ( + e.relatedTarget && + !document + .getElementById('nav-main') + ?.contains(e.relatedTarget as HTMLElement) + ) { + navClose() + } + }) + document.addEventListener('astro:before-preparation', () => { document.getElementById('loading-indicator')?.classList.remove('hidden') }) @@ -78,6 +95,24 @@ const { title = '小帕的小窝' } = Astro.props requestAnimationFrame(navClose) document.getElementById('loading-indicator')?.classList.add('hidden') }) + + document.addEventListener('astro:page-load', () => { + document.querySelectorAll('#nav-main li:has(a)').forEach((li) => { + console.log(li) + const child = li.querySelector('a') + if (!child) { + li.classList.add('url-here') + return + } + if ( + window.location.href.replace(/\/$/, '') == child.href.replace(/\/$/, '') + ) { + li.classList.add('url-here') + } else { + li.classList.remove('url-here') + } + }) + })