Files
personal/app/work/[slug]/page.tsx
T
virtheart e4ee38175e fix: 详情页滚动与多余背景 — 对齐原站路由级 canvas 生命周期
- HeroScene/LoadingOverlay 仅在 "/" 渲染(原 canvas/set:详情页 reveal 后
  卸载 canvas;entry 幕布是主页专属流程)——详情页不再有贴纸/背景 FX/玻璃
  模型等"多余背景",也没有 loading 幕布
- 详情页滚动容器改为常规文档流:我们的 Lenis 是 window 级,原版的嵌套
  overflow-y-auto 容器会吞掉滚轮导致页面不能滚动;窗口原生滚动接管
- SmoothScroller 按路由启停 Lenis(原 95212:主页 ReactLenis、详情页原生
  滚动),路由切换时滚动复位到顶部(转场遮罩盖住跳变)
- CDP 实测:详情页 wheel/End 滚动 ✅、canvas=0、幕布=0;返回主页后
  canvas/Lenis/滚动条恢复、wheel 平滑滚动 ✅
2026-09-01 20:57:50 +08:00

271 lines
9.7 KiB
TypeScript

"use client";
/**
* Work detail pages — /work/[slug] rendering the original MDX article
* markup 1:1 (from https://haoqi.design/reunimos et al.):
*
* <div class="fixed inset-0 w-full h-full">
* <div class="w-full h-full overflow-y-auto overscroll-contain no-scrollbar">
* <article data-mdx-article class="mx-auto px-6 py-18 lg:py-24 w-full
* max-w-[880px] text-l1">
* <header class="pt-[10vh]"> h1 + date + hr + year </header>
* <div class="[&_p+p]:mt-3 …"> blocks </div>
* </article>
*
* Content comes from content/workArticles.ts (extracted from the live
* pages). Passcode-protected scopes (/2026) render the unlock screen when
* locked, exactly like the original.
*/
import { Suspense, useMemo } from "react";
import Link from "next/link";
import { useParams } from "next/navigation";
import {
WORK_ARTICLES,
type ArticleBlock,
type InlineSeg,
} from "@/content/workArticles";
import { usePasscodeAllowed } from "@/components/dom/PasscodeAccess";
import { useRouteTransitionController } from "@/lib/routeTransition";
import { PasscodeUnlockScreen } from "@/components/dom/PasscodeUnlockScreen";
import { buildPasscodeUnlockHref, primaryPasscodePath, scopeToPath } from "@/lib/passcode";
import CustomScrollbar from "@/components/dom/CustomScrollbar";
const PROSE_CLASS =
"[&_p+p]:mt-3 [&_p]:mb-0 text-l2 [&_p]:text-sm [&_p]:text-l1 [&_p]:leading-relaxed lg:[&_p]:text-base";
function Inline({ segs }: { segs: InlineSeg[] }) {
return (
<>
{segs.map((s, i) =>
s.t === "link" ? (
<a
key={i}
href={s.href}
target="_blank"
rel="noopener noreferrer"
className="inline text-l1 underline underline-offset-[0.08em] decoration-solid decoration-(--label-3) transition-[text-decoration-color] duration-150 ease-out lg:[@media(hover:hover)]:hover:decoration-(--label-1)"
>
{s.v}
</a>
) : (
<span key={i}>{s.v}</span>
)
)}
</>
);
}
function Block({ block }: { block: ArticleBlock }) {
switch (block.type) {
case "p":
return (
<p>
<Inline segs={block.segs} />
</p>
);
case "h2":
return <h2 className="mt-8 font-bold text-xl! text-l1">{block.text}</h2>;
case "h3":
return <h3 className="mt-6 font-bold text-lg! text-l1">{block.text}</h3>;
case "img":
// eslint-disable-next-line @next/next/no-img-element -- original uses plain img with cursor-zoom-in
return (
<img
src={block.src}
alt=""
crossOrigin="anonymous"
loading="lazy"
decoding="async"
className="block w-full h-auto cursor-zoom-in select-none border border-line bg-[rgba(var(--label-d),0.05)]"
/>
);
case "hr":
return <hr className="my-8 h-px w-full border-0 bg-line" />;
case "list":
return block.ordered ? (
<ol className="list-decimal my-0 pl-5 space-y-0">
{block.items.map((li, i) => (
<li key={i} className="text-l1 leading-relaxed">
<Inline segs={li} />
</li>
))}
</ol>
) : (
<ul className="list-disc my-0 pl-5 space-y-0">
{block.items.map((li, i) => (
<li key={i} className="text-l1 leading-relaxed">
<Inline segs={li} />
</li>
))}
</ul>
);
case "quote":
return (
<blockquote className="border-l-4 border-(--selection-bg) pl-4 text-l2">
{block.items.map((q, i) => (
<p key={i} className="text-l2">
{q}
</p>
))}
</blockquote>
);
case "code":
return (
<pre className="my-4 overflow-x-auto rounded bg-[rgba(var(--label-d),0.08)] p-3 font-mono text-[0.9em] text-l1">
<code>{block.text}</code>
</pre>
);
default:
return null;
}
}
function Article({ slug }: { slug: string }) {
const article = WORK_ARTICLES[slug];
if (!article) {
return (
<>
<article className="mx-auto px-6 py-18 lg:py-24 w-full max-w-[880px] text-l1">
<header className="pt-[10vh]">
<h1 className="font-bold text-3xl! text-l1 lg:text-5xl! leading-tight tracking-tight">
404
</h1>
<p className="mt-1 text-l2! text-sm! lg:text-base! leading-relaxed">
No article for this work yet.
</p>
<div className="mt-2 border-line border-b" />
<p className="pt-3 text-l2! text-sm! lg:text-base! leading-relaxed">
<Link className="underline underline-offset-4" href="/">
← Home
</Link>
</p>
</header>
</article>
</>
);
}
return (
<>
{/* The window (Lenis) is the scroller — the original nests its own
overflow container per route because its Lenis wraps <main>; our
Lenis is window-level, so a nested overflow div would swallow the
wheel and kill scrolling. */}
<article
data-mdx-article="true"
className="mx-auto px-6 py-18 lg:py-24 w-full max-w-[880px] text-l1"
>
<header className="pt-[10vh]">
<h1 className="font-bold text-3xl! text-l1 lg:text-5xl! leading-tight tracking-tight" style={{ fontVariationSettings: '"wdth" 120' }}>
{article.title}
</h1>
<p className="mt-1 tabular-nums text-l2! text-sm! lg:text-base! leading-relaxed">
{article.date}
</p>
<div className="mt-2 border-line border-b" />
<p className="pt-3 text-l2! text-sm! lg:text-base! leading-relaxed">
{article.year}
</p>
</header>
<div className={PROSE_CLASS}>
{article.blocks.map((b, i) => (
<Block key={i} block={b} />
))}
{article.iframe && (
<iframe
width="840"
height="600"
src={article.iframe.src}
title={article.iframe.title}
allowFullScreen
className="mt-8 w-full border-0"
/>
)}
</div>
{article.meta && (
<footer
data-mdx-footer="true"
className="bg-[rgba(var(--label-d),0.03)] mt-16 p-4 lg:p-6 rounded-xl"
>
<div className="mb-5 font-sans font-semibold text-l1 text-base">
Metadata
</div>
<dl className="gap-x-6 gap-y-6 grid grid-cols-2 lg:grid-cols-3">
{article.meta.map(([dt, dd]) => (
<div key={dt} className="flex flex-col gap-1.5">
<dt className="font-sans font-semibold text-l1 text-sm">{dt}</dt>
<dd>
<span className="font-mono tabular-nums text-l2 text-sm">{dd}</span>
</dd>
</div>
))}
</dl>
<div className="my-6 border-line border-t border-dashed" />
<div className="gap-x-6 gap-y-4 grid grid-cols-2 lg:grid-cols-3">
<div className="hidden lg:block font-sans font-semibold text-l1 text-sm">
Links
</div>
<div className="flex flex-col items-start gap-1 font-mono">
<DetailNavLink href="/">Home</DetailNavLink>
<DetailNavLink href="/">Work</DetailNavLink>
<DetailNavLink href="/">Contact</DetailNavLink>
</div>
<div className="flex flex-col items-start gap-1 font-mono">
{["Twitter/X", "Figma", "GitHub"].map((label) => (
<a
key={label}
href="#"
className="relative before:content-[''] before:absolute before:inset-0 before:border-2 before:border-dotted before:border-transparent before:pointer-events-none before:transition-colors before:duration-200 lg:hover:before:border-l1 inline-block -mx-1 px-1 py-0.5 text-l2 lg:hover:text-l1 text-sm transition-colors"
>
{label}
</a>
))}
</div>
</div>
</footer>
)}
</article>
</>
);
}
function DetailNavLink({ href, children }: { href: string; children: string }) {
const { startNavigation } = useRouteTransitionController();
return (
<button
type="button"
onClick={() => startNavigation(href)}
className="relative before:content-[''] before:absolute before:inset-0 before:border-2 before:border-dotted before:border-transparent before:pointer-events-none before:transition-colors before:duration-200 lg:hover:before:border-l1 inline-block -mx-1 px-1 py-0.5 text-l2 lg:hover:text-l1 text-sm transition-colors text-left cursor-pointer"
>
{children}
</button>
);
}
function WorkDetailInner() {
const params = useParams<{ slug: string }>();
const raw = String(params?.slug ?? "");
// /work/2026 is the passcode-protected scope; the others map back to the
// original slugs (/work/reunimos → content key "/reunimos").
const slug = `/${raw}`;
const allowed = usePasscodeAllowed(slug);
if (!allowed) {
// Protected scope (e.g. /2026) renders the unlock screen in place,
// exactly like the original detail route.
return <PasscodeUnlockScreen scope={slug} returnTo={slug} />;
}
return (
<>
<Article slug={slug} />
<CustomScrollbar />
</>
);
}
export default function WorkDetailPage() {
return (
<Suspense fallback={null}>
<WorkDetailInner />
</Suspense>
);
}