From 55f4eb82b730fd0ec20a5e966f3ebd174c356432 Mon Sep 17 00:00:00 2001 From: Ad-closeNN <1709301095@qq.com> Date: Fri, 1 May 2026 23:01:32 +0800 Subject: [PATCH] =?UTF-8?q?fix(viewSource):=20=E4=BF=AE=E5=A4=8D=E4=B8=80?= =?UTF-8?q?=E4=BA=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layouts/Layout.astro | 23 +++++++++++++ src/pages/posts/[...slug].astro | 58 +++++++++++++++++++++++++-------- 2 files changed, 68 insertions(+), 13 deletions(-) diff --git a/src/layouts/Layout.astro b/src/layouts/Layout.astro index 4af5b1a..afdbe10 100644 --- a/src/layouts/Layout.astro +++ b/src/layouts/Layout.astro @@ -559,6 +559,29 @@ const setup = () => { }) window.swup.hooks.on('content:replace', initCustomScrollbar) window.swup.hooks.on('visit:start', (visit: {to: {url: string}}) => { + // 切页前断开 observer、关闭并清理 panel + // @ts-ignore + if (document.body.__copyPageObserver) { + // @ts-ignore + document.body.__copyPageObserver.disconnect(); + // @ts-ignore + document.body.__copyPageObserver = undefined; + } + const copyPagePanel = document.getElementById('copy-page-panel'); + if (copyPagePanel) { + copyPagePanel.classList.add('pointer-events-none', 'opacity-0', '-translate-y-1'); + copyPagePanel.classList.remove('opacity-100', 'translate-y-0'); + // 如果 panel 已被移到 body(portal 模式),直接移除 + if (copyPagePanel.parentElement === document.body) { + copyPagePanel.remove(); + } + } + const copyPageMenu = document.getElementById('copy-page-menu'); + const copyPageArrow = copyPageMenu?.querySelector('.copy-page-arrow'); + const copyPageSwitch = document.getElementById('copy-page-switch'); + if (copyPageArrow) copyPageArrow.classList.remove('rotate-180'); + if (copyPageSwitch) copyPageSwitch.setAttribute('aria-expanded', 'false'); + // change banner height immediately when a link is clicked const bodyElement = document.querySelector('body') if (pathsEqual(visit.to.url, url('/'))) { diff --git a/src/pages/posts/[...slug].astro b/src/pages/posts/[...slug].astro index 1f7f581..aab9ef2 100644 --- a/src/pages/posts/[...slug].astro +++ b/src/pages/posts/[...slug].astro @@ -222,7 +222,7 @@ const isOutdated = entry.data.outdated; -