diff --git a/app/(site)/page.tsx b/app/(site)/page.tsx index 6ea21d7..0591301 100644 --- a/app/(site)/page.tsx +++ b/app/(site)/page.tsx @@ -93,7 +93,7 @@ export default async function Home() { {config.about_p2} {config.about_p2_link_label} diff --git a/app/(site)/work/[slug]/page.tsx b/app/(site)/work/[slug]/page.tsx index 2f09fc2..fc7645a 100644 --- a/app/(site)/work/[slug]/page.tsx +++ b/app/(site)/work/[slug]/page.tsx @@ -35,7 +35,8 @@ import { scrollEnv } from "@/lib/scrollEnv"; import ScrambleReveal from "@/components/dom/ScrambleReveal"; import CustomScrollbar from "@/components/dom/CustomScrollbar"; -export const PENDING_SCROLL_ANCHOR_SESSION_KEY = "hq:pendingScrollAnchor"; +import { PENDING_SCROLL_ANCHOR_SESSION_KEY } from "@/lib/scrollEnv"; +export { PENDING_SCROLL_ANCHOR_SESSION_KEY }; const MDX_HEADING_ANCHOR_OFFSET_PX = 96; const PROSE_CLASS = diff --git a/app/virtheart/(protected)/settings/page.tsx b/app/virtheart/(protected)/settings/page.tsx index 5f92509..22ba87d 100644 --- a/app/virtheart/(protected)/settings/page.tsx +++ b/app/virtheart/(protected)/settings/page.tsx @@ -31,7 +31,6 @@ const FIELD_LABELS: Record = { about_p1: "关于 · 第一段", about_p2: "关于 · 第二段(链接前)", about_p2_link_label: "关于 · 链接文字", - about_p2_link_href: "关于 · 链接地址", footer_headline: "页脚大字(用 | 分行)", contact_email: "联系邮箱", icp_beian: "ICP 备案号(部署国内必填;空则页脚不显示)", @@ -78,7 +77,7 @@ const GROUPS: { id: string; keys: (keyof SiteConfig)[] }[] = [ "intro_brand", ], }, - { id: "about", keys: ["about_p1", "about_p2", "about_p2_link_label", "about_p2_link_href"] }, + { id: "about", keys: ["about_p1", "about_p2", "about_p2_link_label"] }, { id: "footer", keys: ["footer_headline", "contact_email", "icp_beian"] }, { id: "empty", diff --git a/components/dom/Header.tsx b/components/dom/Header.tsx index 7fb24b3..03357c0 100644 --- a/components/dom/Header.tsx +++ b/components/dom/Header.tsx @@ -4,7 +4,8 @@ import { useCallback, useEffect, useRef, useState } from "react"; import ScrambleReveal from "@/components/dom/ScrambleReveal"; import { useShellMedia, type ThemeSetting } from "@/lib/shellMedia"; import { useBgm } from "@/lib/useBgm"; -import { scrollEnv } from "@/lib/scrollEnv"; +import { scrollEnv, PENDING_SCROLL_ANCHOR_SESSION_KEY } from "@/lib/scrollEnv"; +import { usePathname } from "next/navigation"; import { useRouteTransitionController } from "@/lib/routeTransition"; import { useArrowFullscreenPastThreshold, @@ -60,6 +61,21 @@ export default function Header({ const { theme, setTheme, soundEnabled, setSoundEnabled } = useShellMedia(); useBgm(soundEnabled); const { startNavigation } = useRouteTransitionController(); + const pathname = usePathname(); + + // 首页内锚点直达;其它页面(/services、/work/...)则写入跨页锚点后 + // 走路由过渡回首页,由 SmoothScroller 消费并平滑滚动到位。 + const goToSection = useCallback( + (anchor: string) => { + if (pathname === "/") { + scrollEnv.scrollToSection(anchor); + } else { + sessionStorage.setItem(PENDING_SCROLL_ANCHOR_SESSION_KEY, anchor); + startNavigation("/"); + } + }, + [pathname, startNavigation] + ); // Arrow-fullscreen state: past the 0.5 reveal threshold the whole header // (and the hyper-space section) turn white over the black stripe base // (original X = useArrowFullscreenPastThreshold()). @@ -213,21 +229,21 @@ export default function Header({ diff --git a/components/dom/SmoothScroller.tsx b/components/dom/SmoothScroller.tsx index c4e3d0b..20bec1a 100644 --- a/components/dom/SmoothScroller.tsx +++ b/components/dom/SmoothScroller.tsx @@ -5,6 +5,7 @@ import { usePathname } from 'next/navigation'; import Lenis from 'lenis'; import { scrollBus, notifyScroll } from '@/lib/scrollBus'; import { scrollEnv } from '@/lib/scrollEnv'; +import { PENDING_SCROLL_ANCHOR_SESSION_KEY } from "@/lib/scrollEnv"; const clamp01 = (v: number) => Math.min(1, Math.max(0, v)); @@ -61,9 +62,9 @@ export default function SmoothScroller() { // footer "Work"/"Contact" buttons store the anchor in sessionStorage // and navigate "/" through the transition; the home scroller then // smooth-scrolls to it). - const pendingAnchor = sessionStorage.getItem('hq:pendingScrollAnchor'); + const pendingAnchor = sessionStorage.getItem(PENDING_SCROLL_ANCHOR_SESSION_KEY); if (pendingAnchor) { - sessionStorage.removeItem('hq:pendingScrollAnchor'); + sessionStorage.removeItem(PENDING_SCROLL_ANCHOR_SESSION_KEY); const target = document.querySelector(pendingAnchor); if (target) { requestAnimationFrame(() => requestAnimationFrame(() => { diff --git a/lib/db.ts b/lib/db.ts index cf2f3da..6f1774d 100644 --- a/lib/db.ts +++ b/lib/db.ts @@ -186,7 +186,6 @@ function seed() { "全栈开发者,融合产品设计与工程能力,负责从产品构思、界面设计到前后端、跨端客户端的完整应用交付,现阶段深耕 AI 应用开发。", about_p2: "我相信工程塑造可靠的产品,设计赋予它们灵魂;", about_p2_link_label: "我的作品", - about_p2_link_href: "#selected-work", intro_prefix: "我是北极新一,一名横跨设计与工程的全栈开发者:Web 前端与后端、Flutter 客户端、AI 应用开发都有实践,也从产品设计一路做到工程落地。工作之外,我常在 ", intro_suffix: " 上记录与分享这些探索。", diff --git a/lib/scrollEnv.ts b/lib/scrollEnv.ts index 06abc37..c8f988d 100644 --- a/lib/scrollEnv.ts +++ b/lib/scrollEnv.ts @@ -76,3 +76,9 @@ export const scrollEnv = { else (el as HTMLElement).scrollIntoView({ behavior: "smooth" }); }, }; + +/** + * 跨页锚点:详情页/Header 在非首页时把目标 section 存入 sessionStorage, + * startNavigation("/") 回首页后由 SmoothScroller 消费并平滑滚动。 + */ +export const PENDING_SCROLL_ANCHOR_SESSION_KEY = "hq:pendingScrollAnchor"; diff --git a/lib/siteConfig.ts b/lib/siteConfig.ts index aa48f82..45a94a2 100644 --- a/lib/siteConfig.ts +++ b/lib/siteConfig.ts @@ -18,7 +18,6 @@ export type SiteConfig = { about_p1: string; about_p2: string; about_p2_link_label: string; - about_p2_link_href: string; intro_prefix: string; intro_suffix: string; intro_brand: string; @@ -52,7 +51,6 @@ export const CONFIG_KEYS = [ "about_p1", "about_p2", "about_p2_link_label", - "about_p2_link_href", "intro_prefix", "intro_suffix", "intro_brand", @@ -97,7 +95,6 @@ export const CONFIG_GROUPS: { title: string; keys: (keyof SiteConfig)[] }[] = [ "about_p1", "about_p2", "about_p2_link_label", - "about_p2_link_href", ], }, {