This commit is contained in:
z.ai committed 2026-10-08 11:09:37 +08:00
1 parent c1541b80df
commit b4c7908029
97 files changed
+12403 -154

No files matched your search

+82
View File
@@ -0,0 +1,82 @@
"use client";
import { useState } from "react";
import { usePathname, useRouter } from "@/i18n/navigation";
import { useLocale, useTranslations } from "next-intl";
import { Globe } from "lucide-react";
import { routing } from "@/i18n/routing";
import { cn } from "@/lib/utils";
/**
* 语言切换器。
*
* 使用 next-intl 的 usePathname / useRouter,切换语言时保留当前路径,
* 而不是跳回首页。通过 useParams 需要传参的场景在这里不适用,
* 因为本项目的动态段只有 slug,路径本身已经能表达。
*/
export function LocaleSwitcher({ className }: { className?: string }) {
const t = useTranslations("LocaleSwitcher");
const locale = useLocale();
const router = useRouter();
const pathname = usePathname();
const [open, setOpen] = useState(false);
const handleSelect = (nextLocale: string) => {
setOpen(false);
router.replace(pathname, { locale: nextLocale });
};
return (
<div className={cn("relative", className)}>
<button
type="button"
onClick={() => setOpen((value) => !value)}
aria-haspopup="listbox"
aria-expanded={open}
aria-label={t("label")}
className="inline-flex h-9 items-center gap-[6px] rounded-full px-sm text-body-sm text-steel transition-colors duration-150 active:bg-surface"
>
<Globe className="size-4" aria-hidden="true" />
<span className="hidden sm:inline">{t(locale)}</span>
</button>
{open ? (
<>
{/* 点击遮罩关闭菜单 */}
<button
type="button"
tabIndex={-1}
aria-hidden="true"
onClick={() => setOpen(false)}
className="fixed inset-0 z-40 cursor-default"
/>
<ul
role="listbox"
aria-label={t("label")}
className="absolute right-0 z-50 mt-xs min-w-[140px] overflow-hidden rounded-md border border-hairline bg-canvas py-xxs shadow-card"
>
{routing.locales.map((item) => (
<li key={item}>
<button
type="button"
role="option"
aria-selected={item === locale}
onClick={() => handleSelect(item)}
className={cn(
"flex w-full items-center px-md py-xs text-left text-body-sm transition-colors duration-150",
item === locale
? "bg-surface font-medium text-ink"
: "text-steel active:bg-surface",
)}
>
{t(item)}
</button>
</li>
))}
</ul>
</>
) : null}
</div>
);
}
+107
View File
@@ -0,0 +1,107 @@
import { Link } from "@/i18n/navigation";
import { getTranslations } from "next-intl/server";
import { Mail, Rss, SquareArrowOutUpRight } from "lucide-react";
import { siteConfig } from "@/lib/site-config";
/**
* 社交链接图标。
*
* 注意:lucide-react v1.x 已移除品牌图标(Github / Twitter 等),
* 因此这里使用通用图标,由 `label` 文本承载具体含义——
* 图标仅作装饰(aria-hidden),可访问性不依赖它。
*/
const SOCIAL_ICONS = {
github: SquareArrowOutUpRight,
twitter: Rss,
mail: Mail,
} as const;
/**
* 站点页脚。
*
* DESIGN.md 的 footer-region:白底上一道 hairline 顶边,多列分组,
* 分栏标题用 body-sm-medium 深色,链接用 body-sm 灰色。
*/
export async function SiteFooter() {
const t = await getTranslations("Footer");
const tNav = await getTranslations("Nav");
const year = new Date().getFullYear();
return (
<footer className="border-t border-hairline bg-canvas">
<div className="mx-auto w-full max-w-[1280px] px-lg py-section sm:px-xxl">
<div className="grid grid-cols-1 gap-xxl sm:grid-cols-2 lg:grid-cols-4">
{/* 品牌列 */}
<div className="flex flex-col gap-sm lg:col-span-2">
<div className="flex items-center gap-xs text-body-md font-semibold text-ink">
<span
aria-hidden="true"
className="grid size-7 place-items-center rounded-md bg-primary font-mono text-caption font-semibold text-brand-green"
>
&gt;_
</span>
{siteConfig.name}
</div>
<p className="max-w-[360px] text-body-sm text-steel">
{siteConfig.description}
</p>
</div>
{/* 导航列 */}
<nav aria-label={t("navigation")} className="flex flex-col gap-xs">
<h2 className="mb-xs text-body-sm font-medium text-ink">
{t("navigation")}
</h2>
<Link
href="/"
className="py-xxs text-body-sm text-steel transition-colors duration-150 hover:text-ink"
>
{tNav("home")}
</Link>
<Link
href="/about"
className="py-xxs text-body-sm text-steel transition-colors duration-150 hover:text-ink"
>
{tNav("about")}
</Link>
</nav>
{/* 社交列 */}
<div className="flex flex-col gap-xs">
<h2 className="mb-xs text-body-sm font-medium text-ink">
{t("elsewhere")}
</h2>
<ul className="flex flex-col gap-xxs">
{siteConfig.social.map((item) => {
const Icon = SOCIAL_ICONS[item.icon];
return (
<li key={item.label}>
<a
href={item.href}
target={item.href.startsWith("mailto:") ? undefined : "_blank"}
rel="noopener noreferrer"
className="inline-flex items-center gap-xs py-xxs text-body-sm text-steel transition-colors duration-150 hover:text-ink"
>
<Icon className="size-4" aria-hidden="true" />
{item.label}
</a>
</li>
);
})}
</ul>
</div>
</div>
<div className="mt-xxl flex flex-col gap-xs border-t border-hairline-soft pt-lg text-caption text-steel sm:flex-row sm:items-center sm:justify-between">
<p>
© {year} {siteConfig.name}. {t("rights")}
</p>
<p className="font-mono">{t("builtWith")}</p>
</div>
</div>
</footer>
);
}
+154
View File
@@ -0,0 +1,154 @@
"use client";
import { useEffect, useState } from "react";
import { Link, usePathname } from "@/i18n/navigation";
import { useTranslations } from "next-intl";
import { AnimatePresence, motion, useReducedMotion } from "motion/react";
import { Menu, X } from "lucide-react";
import { cn } from "@/lib/utils";
import { LocaleSwitcher } from "./locale-switcher";
const NAV_ITEMS = [
{ href: "/", key: "home" },
{ href: "/about", key: "about" },
] as const;
/**
* 站点头部导航。
*
* DESIGN.md:粘性白色导航条,高度约 64px,底部分割线 1px hairline-soft。
* 桌面端横向展示链接与 CTA;移动端(<1024px)折叠为抽屉菜单。
*/
export function SiteHeader() {
const t = useTranslations("Nav");
const pathname = usePathname();
const [menuOpen, setMenuOpen] = useState(false);
const shouldReduceMotion = useReducedMotion();
// 菜单打开时锁定页面滚动(与外部系统 document.body 同步)
useEffect(() => {
if (!menuOpen) {
return;
}
const original = document.body.style.overflow;
document.body.style.overflow = "hidden";
return () => {
document.body.style.overflow = original;
};
}, [menuOpen]);
const isActive = (href: string) =>
href === "/" ? pathname === "/" : pathname.startsWith(href);
return (
<header className="sticky top-0 z-40 border-b border-hairline-soft bg-canvas/85 backdrop-blur-md">
<div className="mx-auto flex h-16 w-full max-w-[1280px] items-center justify-between gap-md px-lg sm:px-xxl">
{/* 品牌标识 */}
<Link
href="/"
className="flex items-center gap-xs text-body-md font-semibold text-ink"
aria-label={t("home")}
>
<span
aria-hidden="true"
className="grid size-7 place-items-center rounded-md bg-primary font-mono text-caption font-semibold text-brand-green"
>
&gt;_
</span>
<span className="hidden sm:inline">个人博客</span>
</Link>
{/* 桌面端导航 */}
<nav
aria-label={t("home")}
className="hidden items-center gap-xxs md:flex"
>
{NAV_ITEMS.map((item) => (
<Link
key={item.href}
href={item.href}
aria-current={isActive(item.href) ? "page" : undefined}
className={cn(
"rounded-full px-md py-xs text-body-sm transition-colors duration-150",
isActive(item.href)
? "font-medium text-ink"
: "text-steel active:bg-surface",
)}
>
{t(item.key)}
</Link>
))}
</nav>
<div className="flex items-center gap-xxs">
<LocaleSwitcher />
{/* GitHub 入口(桌面端) */}
<a
href="https://github.com"
target="_blank"
rel="noopener noreferrer"
className="hidden h-9 items-center rounded-full bg-primary px-lg text-button-md text-on-primary transition-colors duration-150 active:bg-charcoal md:inline-flex"
>
GitHub
</a>
{/* 移动端菜单开关 */}
<button
type="button"
onClick={() => setMenuOpen((value) => !value)}
aria-expanded={menuOpen}
aria-controls="mobile-navigation"
aria-label={menuOpen ? t("closeMenu") : t("openMenu")}
className="grid size-10 place-items-center rounded-full text-ink transition-colors duration-150 active:bg-surface md:hidden"
>
{menuOpen ? (
<X className="size-5" aria-hidden="true" />
) : (
<Menu className="size-5" aria-hidden="true" />
)}
</button>
</div>
</div>
{/* 移动端抽屉 */}
<AnimatePresence>
{menuOpen ? (
<motion.nav
id="mobile-navigation"
aria-label={t("home")}
initial={shouldReduceMotion ? false : { opacity: 0, height: 0 }}
animate={{ opacity: 1, height: "auto" }}
exit={shouldReduceMotion ? { opacity: 0 } : { opacity: 0, height: 0 }}
transition={{ duration: 0.2, ease: [0.22, 1, 0.36, 1] }}
className="overflow-hidden border-t border-hairline-soft bg-canvas md:hidden"
>
<ul className="flex flex-col px-lg py-sm sm:px-xxl">
{NAV_ITEMS.map((item) => (
<li key={item.href}>
<Link
href={item.href}
// 点击后立即收起抽屉,避免依赖路由变化的副作用
onClick={() => setMenuOpen(false)}
aria-current={isActive(item.href) ? "page" : undefined}
className={cn(
// 触控目标 ≥ 44px
"flex min-h-11 items-center rounded-md px-sm text-body-md transition-colors duration-150",
isActive(item.href)
? "font-medium text-ink"
: "text-steel active:bg-surface",
)}
>
{t(item.key)}
</Link>
</li>
))}
</ul>
</motion.nav>
) : null}
</AnimatePresence>
</header>
);
}