feat(docs): optimize mobile layout and localized metadata

This commit is contained in:
t8y2
2026-07-31 20:19:30 +08:00
parent c43e8455c4
commit ce3bb09796
28 changed files with 909 additions and 396 deletions
@@ -46,12 +46,23 @@ export function HeroProductStage() {
>
<div className="relative aspect-[16/10] overflow-hidden">
{productSlides.map((slide, index) => (
<img alt={slide.alt} aria-hidden={index !== activeSlide} className="landing-product-slide absolute inset-0 z-[1] w-full h-full object-cover object-left-top" data-active={index === activeSlide} key={slide.src} src={slide.src} />
<img
alt={slide.alt}
aria-hidden={index !== activeSlide}
className="landing-product-slide absolute inset-0 z-[1] w-full h-full object-cover object-left-top"
data-active={index === activeSlide}
decoding="async"
fetchPriority={index === 0 ? "high" : "auto"}
key={slide.src}
loading={index === 0 ? "eager" : "lazy"}
sizes="(max-width: 760px) calc(100vw - 36px), (max-width: 1040px) calc(100vw - 56px), 1180px"
src={slide.src}
/>
))}
</div>
<div className="landing-product-dots absolute right-[18px] bottom-4 z-[5] flex gap-[7px] items-center rounded-full p-1.5 max-[760px]:right-3 max-[760px]:bottom-[11px]" aria-label="DBX product screenshots">
<div className="landing-product-dots absolute right-[18px] bottom-4 z-[5] flex items-center rounded-full p-1 max-[760px]:right-2 max-[760px]:bottom-2" aria-label="DBX product screenshots">
{productSlides.map((slide, index) => (
<button aria-current={index === activeSlide} aria-label={`Show ${slide.label} screenshot`} key={slide.src} onClick={() => setActiveSlide(index)} title={slide.label} type="button" className="block w-[9px] h-[9px] border-0 rounded-full p-0 cursor-pointer">
<button aria-current={index === activeSlide} aria-label={`Show ${slide.label} screenshot`} key={slide.src} onClick={() => setActiveSlide(index)} title={slide.label} type="button" className="landing-product-dot block size-8 border-0 rounded-full p-0 cursor-pointer">
<span>{slide.label}</span>
</button>
))}
@@ -17,12 +17,12 @@ export function InfiniteMovingCards({ items, direction = "left", speed = "normal
const repeatedItems = [...items, ...items];
return (
<div className="landing-testimonial-marquee flex overflow-hidden select-none" data-direction={direction} data-speed={speed} aria-label="Testimonials">
<div className="landing-testimonial-marquee flex overflow-hidden select-none" data-direction={direction} data-speed={speed} aria-label="Testimonials" tabIndex={0}>
<div className="landing-testimonial-track flex w-max min-w-full gap-3.5 px-[7px]">
{repeatedItems.map((item, index) => (
<figure className="landing-testimonial-card flex-[0_0_340px] min-h-[188px] rounded-[9px] m-0 p-[22px] max-[760px]:flex-[0_0_286px] max-[760px]:min-h-[210px] max-[760px]:p-[18px]" key={`${item.name}-${index}`}>
<figure aria-hidden={index >= items.length} className="landing-testimonial-card flex-[0_0_340px] min-h-[188px] rounded-[9px] m-0 p-[22px] max-[760px]:flex-[0_0_286px] max-[760px]:min-h-[210px] max-[760px]:p-[18px]" key={`${item.name}-${index}`}>
<div className="flex gap-3 items-center">
<img className="w-[42px] h-[42px] shrink-0 border border-[rgba(178,200,230,0.18)] rounded-full bg-[rgba(255,255,255,0.04)] object-cover" src={item.avatar} alt="" width={42} height={42} />
<img className="w-[42px] h-[42px] shrink-0 border border-[rgba(178,200,230,0.18)] rounded-full bg-[rgba(255,255,255,0.04)] object-cover" src={item.avatar} alt="" width={42} height={42} loading="lazy" decoding="async" />
<figcaption>
<strong className="block text-landing-ink text-[15px] font-[740] leading-[1.25]">{item.name}</strong>
<span className="block mt-[3px] text-landing-muted text-xs leading-[1.35]">{item.role}</span>
@@ -192,6 +192,7 @@
.directoryGrid strong { display: block; overflow: hidden; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.directoryGrid small { display: block; margin-top: 4px; color: var(--muted); font-size: 10px; }
.directoryGrid svg { color: #718396; }
.directoryToggle { display: none; width: 100%; min-height: 46px; margin-top: 12px; border: 1px solid rgba(155, 176, 205, 0.2); border-radius: 10px; background: rgba(17, 21, 29, 0.88); color: var(--ink); font-size: 13px; font-weight: 740; cursor: pointer; }
.empty { padding: 60px; border: 1px dashed rgba(155, 176, 205, 0.2); border-radius: 12px; color: var(--muted); text-align: center; }
.modalBackdrop { position: fixed; z-index: 100; inset: 0; display: grid; place-items: center; padding: 24px; background: rgba(31, 27, 66, 0.74); backdrop-filter: blur(16px); }
@@ -237,6 +238,8 @@
.directorySection { padding-right: 18px; padding-left: 18px; }
.directoryHeader { align-items: stretch; flex-direction: column; }
.directoryGrid { grid-template-columns: 1fr; }
.directoryGrid[data-expanded="false"] > :nth-child(n + 25) { display: none; }
.directoryToggle { display: block; }
.certificatePreview { min-height: 390px; padding: 30px; }
.certificatePreview > p { max-width: 68%; }
.previewSeal { right: 34px; width: 74px; height: 74px; font-size: 22px; }
@@ -21,6 +21,8 @@ const copy = {
stars: "GitHub stars",
directory: "Contributor directory",
search: "Search GitHub login",
showAll: "Show all contributors",
showLess: "Show fewer contributors",
noResults: "No matching contributor.",
signedInAs: "Verified as",
claim: "Open my certificate",
@@ -47,6 +49,8 @@ const copy = {
stars: "个 GitHub Star",
directory: "完整贡献者名单",
search: "搜索 GitHub 用户名",
showAll: "展开全部贡献者",
showLess: "收起贡献者名单",
noResults: "没有匹配的贡献者。",
signedInAs: "已验证身份",
claim: "打开我的证书",
@@ -185,6 +189,7 @@ export function ContributorsExperience({ data, lang }: { data: ContributorActivi
const [auth, setAuth] = useState<AuthState>({ status: "loading" });
const [query, setQuery] = useState("");
const [certificateOpen, setCertificateOpen] = useState(false);
const [directoryExpanded, setDirectoryExpanded] = useState(false);
const mergedPullRequests = useMemo(() => data.contributors.reduce((total, contributor) => total + contributor.mergedPullRequests, 0), [data.contributors]);
const commits = useMemo(() => data.contributors.reduce((total, contributor) => total + contributor.commits, 0), [data.contributors]);
@@ -248,7 +253,7 @@ export function ContributorsExperience({ data, lang }: { data: ContributorActivi
<div className={styles.heroCertificate}>
<div className={styles.certificatePreview}>
<div className={styles.previewTop}><span><img src="/logo.png" alt="DBX" width={28} height={28} />DBX</span><ShieldCheck size={18} /></div>
<div className={styles.previewTop}><span><img src="/logo.png" alt="" aria-hidden="true" width={28} height={28} />DBX</span><ShieldCheck size={18} /></div>
<small>{text.certificate}</small>
<strong>@{verifiedContributor?.login ?? "YOUR_NAME"}</strong>
<p>{text.certificateBody}</p>
@@ -271,7 +276,7 @@ export function ContributorsExperience({ data, lang }: { data: ContributorActivi
<section className={styles.directorySection}>
<div className={styles.directoryHeader}><div><h2>{text.directory}</h2></div><label><Search size={17} /><input value={query} onChange={(event) => setQuery(event.target.value)} placeholder={text.search} /></label></div>
{filtered.length ? (
<div className={styles.directoryGrid}>
<div className={styles.directoryGrid} data-expanded={directoryExpanded || query.trim().length > 0}>
{filtered.map((contributor) => (
<a key={contributor.login} href={contributor.profileUrl} target="_blank" rel="noopener noreferrer">
<img src={contributor.avatarUrl} alt="" width={46} height={46} loading="lazy" />
@@ -281,13 +286,18 @@ export function ContributorsExperience({ data, lang }: { data: ContributorActivi
))}
</div>
) : <div className={styles.empty}>{text.noResults}</div>}
{filtered.length > 24 && query.trim().length === 0 ? (
<button type="button" className={styles.directoryToggle} aria-expanded={directoryExpanded} onClick={() => setDirectoryExpanded((current) => !current)}>
{directoryExpanded ? text.showLess : `${text.showAll} (${filtered.length})`}
</button>
) : null}
</section>
{certificateOpen && verifiedContributor ? (
<div className={styles.modalBackdrop} role="presentation" onMouseDown={(event) => { if (event.target === event.currentTarget) setCertificateOpen(false); }}>
<section className={styles.modal} role="dialog" aria-modal="true" aria-label={text.certificate}>
<div className={styles.fullCertificate}>
<div className={styles.previewTop}><span><img src="/logo.png" alt="DBX" width={30} height={30} />DBX · OPEN SOURCE DATABASE TOOL</span><ShieldCheck size={20} /></div>
<div className={styles.previewTop}><span><img src="/logo.png" alt="" aria-hidden="true" width={30} height={30} />DBX · OPEN SOURCE DATABASE TOOL</span><ShieldCheck size={20} /></div>
<span className={styles.verifiedText}>{text.verified}</span>
<small>{text.certificate}</small>
<em>{text.awardedTo}</em>
+53 -47
View File
@@ -22,56 +22,62 @@ function formatDate(dateStr: string, lang: string) {
return d.toLocaleDateString("en-US", { year: "numeric", month: "long", day: "numeric" });
}
function ReleaseCard({ release, lang }: { release: ChangelogRelease; lang: string }) {
function ReleaseCard({ release, lang, featured }: { release: ChangelogRelease; lang: string; featured: boolean }) {
const t = lang === "cn" ? { publishedOn: "发布于", download: "下载", seeGitHub: "查看 GitHub Release 获取详情" } : { publishedOn: "Published on", download: "Download", seeGitHub: "See GitHub Release for details" };
return (
<div className="py-12 border-t border-[rgba(155,176,205,0.18)]">
{/* Header */}
<div className="flex items-center justify-between gap-4 mb-8">
<div className="flex items-center gap-4">
<span className="flex items-center gap-1.5 px-3.5 py-1.5 rounded-full border border-[rgba(155,176,205,0.25)] text-sm font-semibold text-[#e2e8f0]">
<Tag size={13} className="text-[#6ea8ff]" />
{release.tag.replace("v", "")}
</span>
<span className="text-[15px] text-[#64748b]">
{t.publishedOn} {formatDate(release.date, lang)}
</span>
<details className="changelog-release border-t border-[rgba(155,176,205,0.18)]" open={featured || undefined}>
<summary className="changelog-release-summary min-h-[72px] cursor-pointer list-none items-center justify-between gap-4 py-4 text-[#e2e8f0]">
<span className="min-w-0">
<strong className="block truncate text-[17px] font-[720]">Release {release.tag}</strong>
<span className="mt-1 block text-xs text-[#64748b]">{formatDate(release.date, lang)}</span>
</span>
<ChevronDown className="changelog-release-chevron shrink-0 text-[#6ea8ff]" size={18} />
</summary>
<div className="changelog-release-body py-12 max-[760px]:py-8">
<div className="flex items-center justify-between gap-4 mb-8 max-[760px]:items-start max-[760px]:flex-wrap max-[760px]:mb-6">
<div className="flex items-center gap-4 max-[760px]:flex-wrap max-[760px]:gap-2.5">
<span className="flex items-center gap-1.5 px-3.5 py-1.5 rounded-full border border-[rgba(155,176,205,0.25)] text-sm font-semibold text-[#e2e8f0]">
<Tag size={13} className="text-[#6ea8ff]" />
{release.tag.replace("v", "")}
</span>
<span className="text-[15px] text-[#64748b] max-[760px]:text-[13px]">
{t.publishedOn} {formatDate(release.date, lang)}
</span>
</div>
<a href={`https://github.com/t8y2/dbx/releases/tag/${release.tag}`} target="_blank" rel="noopener noreferrer" className="flex min-h-11 items-center gap-1.5 px-4 rounded-full border border-[rgba(155,176,205,0.25)] text-sm text-[#e2e8f0] hover:border-[rgba(155,176,205,0.4)] transition-colors">
{t.download}
<ChevronDown size={14} />
</a>
</div>
<a href={`https://github.com/t8y2/dbx/releases/tag/${release.tag}`} target="_blank" rel="noopener noreferrer" className="flex items-center gap-1.5 px-4 py-2 rounded-full border border-[rgba(155,176,205,0.25)] text-sm text-[#e2e8f0] hover:border-[rgba(155,176,205,0.4)] transition-colors">
{t.download}
<ChevronDown size={14} />
</a>
<h2 className="text-[28px] font-[720] text-[#f7fbff] mb-10 max-[760px]:text-2xl max-[760px]:mb-7">Release {release.tag}</h2>
{release.sections.map((section, sectionIndex) => (
<div key={sectionIndex} className={sectionIndex > 0 ? "mt-10 max-[760px]:mt-8" : ""}>
<h3 className="text-xl font-bold text-[#f7fbff] mb-5 max-[760px]:text-lg max-[760px]:mb-4">{sectionLabels[section.type]?.[lang] || section.title}</h3>
<ul className="space-y-3">
{section.items.map((item, itemIndex) => (
<li key={itemIndex} className="flex gap-3 text-[15px] leading-relaxed text-[#b8c5d6] max-[760px]:text-sm">
<span className="mt-2 w-1.5 h-1.5 rounded-full bg-[#475569] shrink-0" />
<span>
{item.desc ? (
<>
{item.title},{item.desc}
</>
) : (
item.title
)}
</span>
</li>
))}
</ul>
</div>
))}
{release.sections.length === 0 && <p className="text-[15px] text-[#64748b] italic">{t.seeGitHub}</p>}
</div>
{/* Title */}
<h2 className="text-[28px] font-[720] text-[#f7fbff] mb-10">Release {release.tag}</h2>
{/* Sections */}
{release.sections.map((section, si) => (
<div key={si} className={si > 0 ? "mt-10" : ""}>
<h3 className="text-xl font-bold text-[#f7fbff] mb-5">{sectionLabels[section.type]?.[lang] || section.title}</h3>
<ul className="space-y-3">
{section.items.map((item, ii) => (
<li key={ii} className="flex gap-3 text-[15px] leading-relaxed text-[#b8c5d6]">
<span className="mt-2 w-1.5 h-1.5 rounded-full bg-[#475569] shrink-0" />
<span>
{item.desc ? (
<>
{item.title},{item.desc}
</>
) : (
item.title
)}
</span>
</li>
))}
</ul>
</div>
))}
{release.sections.length === 0 && <p className="text-[15px] text-[#64748b] italic">{t.seeGitHub}</p>}
</div>
</details>
);
}
@@ -101,8 +107,8 @@ export function ChangelogList({ releases, lang }: { releases: ChangelogRelease[]
return (
<>
{visible.map((release) => (
<ReleaseCard key={release.tag} release={release} lang={lang} />
{visible.map((release, index) => (
<ReleaseCard key={release.tag} release={release} lang={lang} featured={index === 0} />
))}
{hasMore && (
<div ref={sentinelRef} className="flex justify-center py-12 text-[#64748b] text-sm">
@@ -0,0 +1,37 @@
"use client";
import type { ReactNode } from "react";
import { useState } from "react";
export function ExpandableDatabaseGrid({ children, lang }: { children: ReactNode; lang: "en" | "cn" }) {
const [expanded, setExpanded] = useState(false);
const label = expanded
? lang === "cn"
? "收起数据库列表"
: "Show fewer databases"
: lang === "cn"
? "展开全部数据库"
: "Show all databases";
return (
<>
<div
id="landing-database-grid"
className="landing-database-grid grid grid-cols-9 gap-3 max-[1240px]:grid-cols-7 max-[960px]:grid-cols-5 max-[640px]:grid-cols-4 max-[360px]:grid-cols-3 max-[760px]:gap-2"
data-expanded={expanded}
>
{children}
</div>
<button
type="button"
className="landing-database-toggle mt-3 hidden min-h-11 w-full items-center justify-center gap-2 rounded-lg border border-landing-line bg-landing-panel px-4 text-sm font-[650] text-landing-ink max-[760px]:flex"
aria-controls="landing-database-grid"
aria-expanded={expanded}
onClick={() => setExpanded((current) => !current)}
>
<span>{label}</span>
<span aria-hidden="true">{expanded ? "−" : "+"}</span>
</button>
</>
);
}
+33 -19
View File
@@ -51,6 +51,17 @@ export function InstallTabs({ lang, version }: InstallTabsProps) {
setPlatformId(detectPlatformId());
}, []);
useEffect(() => {
if (!open) return;
const closeOnEscape = (event: KeyboardEvent) => {
if (event.key === "Escape") setOpen(false);
};
window.addEventListener("keydown", closeOnEscape);
return () => window.removeEventListener("keydown", closeOnEscape);
}, [open]);
const primary = useMemo(() => options.find((o) => o.id === platformId) ?? options[0], [options, platformId]);
const menuOptions = useMemo(() => options.filter((o) => o.id !== platformId), [options, platformId]);
@@ -63,32 +74,35 @@ export function InstallTabs({ lang, version }: InstallTabsProps) {
setOpen(false);
}
}}
onMouseEnter={() => setOpen(true)}
onMouseLeave={() => setOpen(false)}
>
<a
aria-controls="landing-install-menu"
aria-expanded={open}
aria-haspopup="listbox"
className="landing-install-trigger grid grid-cols-[auto_minmax(0,1fr)_auto] gap-4 items-center w-[min(340px,calc(100vw-48px))] min-h-[68px] border-0 rounded-full mx-auto px-6 cursor-pointer"
href={primary.href}
onFocus={() => setOpen(true)}
>
<PlatformIcon id={primary.id} size={30} variant="dark" />
<span className="grid gap-0.5 min-w-0">
<strong className="overflow-hidden text-[15px] font-[780] leading-[1.2] truncate">{downloadLabel[lang]}</strong>
<small className="overflow-hidden text-xs font-[520] leading-tight truncate text-[color-mix(in_srgb,#0f172a_48%,#94a3b8)]">{primary.label}</small>
</span>
<ChevronDown size={18} />
</a>
<div className="landing-install-trigger grid grid-cols-[minmax(0,1fr)_52px] items-stretch w-[min(340px,calc(100vw-36px))] min-h-[68px] border-0 rounded-full mx-auto overflow-hidden">
<a className="landing-install-primary grid grid-cols-[auto_minmax(0,1fr)] gap-4 items-center min-w-0 px-6 max-[360px]:gap-3 max-[360px]:px-5" href={primary.href}>
<PlatformIcon id={primary.id} size={30} variant="dark" />
<span className="grid gap-0.5 min-w-0 text-left">
<strong className="overflow-hidden text-[15px] font-[780] leading-[1.2] truncate">{downloadLabel[lang]}</strong>
<small className="overflow-hidden text-xs font-[520] leading-tight truncate text-[color-mix(in_srgb,#0f172a_48%,#94a3b8)]">{primary.label}</small>
</span>
</a>
<button
type="button"
aria-controls="landing-install-menu"
aria-expanded={open}
aria-haspopup="menu"
aria-label={lang === "cn" ? "显示其他下载选项" : "Show other download options"}
className="landing-install-toggle grid place-items-center border-0 border-l border-l-[rgba(15,23,42,0.12)] bg-transparent text-[#5f6876] cursor-pointer"
onClick={() => setOpen((current) => !current)}
>
<ChevronDown size={18} />
</button>
</div>
<div
className="landing-install-menu absolute z-30 top-[calc(100%+12px)] left-1/2 -translate-x-1/2 grid w-[min(300px,calc(100vw-48px))] border border-[rgba(155,176,205,0.17)] rounded-xl py-1.5"
id="landing-install-menu"
role="listbox"
role="menu"
aria-label={lang === "cn" ? "下载选项" : "Download options"}
>
{menuOptions.map((item) => (
<a aria-selected="false" className="landing-install-option grid grid-cols-[24px_minmax(0,1fr)_18px] gap-3 items-center min-w-0 border-0 px-[18px] py-3 bg-transparent text-left cursor-pointer" href={item.href} key={item.id} role="option">
<a className="landing-install-option grid grid-cols-[24px_minmax(0,1fr)_18px] gap-3 items-center min-h-11 min-w-0 border-0 px-[18px] py-3 bg-transparent text-left cursor-pointer" href={item.href} key={item.id} role="menuitem">
<PlatformIcon id={item.id} size={20} variant="light" />
<strong className="overflow-hidden text-sm font-[640] leading-[1.2] truncate">{item.label}</strong>
<Download size={15} aria-hidden="true" />
+5 -5
View File
@@ -27,8 +27,8 @@ export function LandingFooter({ lang }: { lang: "en" | "cn" }) {
<div className="max-w-[1180px] mx-auto px-7 py-7 max-[760px]:px-[18px]">
<div className="flex items-center justify-between gap-4 max-[760px]:flex-col max-[760px]:gap-3 max-[760px]:text-center">
{/* Logo */}
<Link href={`/${lang}`} className="flex items-center gap-2.5 text-[var(--color-landing-ink)] text-lg font-[820] shrink-0">
<img src="/logo.png" alt="DBX" width={22} height={22} />
<Link href={`/${lang}`} className="flex min-h-11 items-center gap-2.5 text-[var(--color-landing-ink)] text-lg font-[820] shrink-0">
<img src="/logo.png" alt="" aria-hidden="true" width={22} height={22} />
<span>DBX</span>
</Link>
@@ -37,13 +37,13 @@ export function LandingFooter({ lang }: { lang: "en" | "cn" }) {
{/* Repo icons */}
<div className="flex items-center gap-3 shrink-0">
<a href="https://github.com/t8y2/dbx" target="_blank" rel="noopener noreferrer" className="text-[var(--color-landing-muted)] hover:text-[var(--color-landing-ink)] transition-colors" aria-label="GitHub">
<a href="https://github.com/t8y2/dbx" target="_blank" rel="noopener noreferrer" className="inline-flex size-11 items-center justify-center text-[var(--color-landing-muted)] hover:text-[var(--color-landing-ink)] transition-colors" aria-label="GitHub">
<GithubIcon />
</a>
<a href="https://cnb.cool/dbxio.com/dbx" target="_blank" rel="noopener noreferrer" className="opacity-40 hover:opacity-100 transition-opacity" aria-label="CNB">
<a href="https://cnb.cool/dbxio.com/dbx" target="_blank" rel="noopener noreferrer" className="inline-flex size-11 items-center justify-center opacity-40 hover:opacity-100 transition-opacity" aria-label="CNB">
<img src="/icons/cnb.svg" alt="CNB" width={18} height={18} />
</a>
<a href="https://atomgit.com/t8y2/dbx" target="_blank" rel="noopener noreferrer" className="opacity-40 hover:opacity-100 transition-opacity" aria-label="AtomGit">
<a href="https://atomgit.com/t8y2/dbx" target="_blank" rel="noopener noreferrer" className="inline-flex size-11 items-center justify-center opacity-40 hover:opacity-100 transition-opacity" aria-label="AtomGit">
<img src="/icons/atomgit.png" alt="AtomGit" width={18} height={18} />
</a>
</div>
+96 -30
View File
@@ -1,8 +1,8 @@
"use client";
import Link from "next/link";
import { Github } from "lucide-react";
import { useEffect, useRef } from "react";
import { Github, Menu, X } from "lucide-react";
import { useEffect, useRef, useState } from "react";
const i18n = {
en: {
@@ -14,12 +14,26 @@ const i18n = {
contributors: "Contributors",
drivers: "Offline Drivers",
langLabel: "Switch to Chinese",
menu: "Open navigation",
closeMenu: "Close navigation",
},
cn: {
home: "首页",
docs: "文档",
changelog: "更新日志",
community: "交流群",
sponsors: "赞助商",
contributors: "贡献者",
drivers: "离线驱动",
langLabel: "切换到英文",
menu: "打开导航",
closeMenu: "关闭导航",
},
cn: { home: "首页", docs: "文档", changelog: "更新日志", community: "交流群", sponsors: "赞助商", contributors: "贡献者", drivers: "离线驱动", langLabel: "切换到英文" },
};
export function LandingNav({ lang, active }: { lang: "en" | "cn"; active?: "home" | "databases" | "changelog" | "community" | "sponsors" | "contributors" | "drivers" }) {
const ref = useRef<HTMLElement>(null);
const [menuOpen, setMenuOpen] = useState(false);
const t = i18n[lang];
const otherLang = lang === "cn" ? "en" : "cn";
const langHrefMap: Record<string, string> = {
@@ -31,6 +45,15 @@ export function LandingNav({ lang, active }: { lang: "en" | "cn"; active?: "home
drivers: `/${otherLang}/drivers`,
};
const langHref = langHrefMap[active ?? ""] ?? `/${otherLang}`;
const navItems = [
{ id: "home", href: `/${lang}`, label: t.home, tabletHidden: false },
{ id: "docs", href: `/${lang}/docs/what-is-dbx`, label: t.docs, tabletHidden: false },
{ id: "changelog", href: `/${lang}/changelog`, label: t.changelog, tabletHidden: false },
{ id: "community", href: `/${lang}/community`, label: t.community, tabletHidden: false },
{ id: "sponsors", href: `/${lang}/sponsors`, label: t.sponsors, tabletHidden: true },
{ id: "contributors", href: `/${lang}/contributors`, label: t.contributors, tabletHidden: true },
{ id: "drivers", href: `/${lang}/drivers`, label: t.drivers, tabletHidden: false },
] as const;
useEffect(() => {
const node = ref.current;
@@ -45,41 +68,84 @@ export function LandingNav({ lang, active }: { lang: "en" | "cn"; active?: "home
return () => window.removeEventListener("scroll", onScroll);
}, []);
useEffect(() => {
if (!menuOpen) return;
const previousOverflow = document.body.style.overflow;
const closeOnEscape = (event: KeyboardEvent) => {
if (event.key === "Escape") setMenuOpen(false);
};
const closeOnDesktop = () => {
if (window.innerWidth > 760) setMenuOpen(false);
};
document.body.style.overflow = "hidden";
window.addEventListener("keydown", closeOnEscape);
window.addEventListener("resize", closeOnDesktop);
return () => {
document.body.style.overflow = previousOverflow;
window.removeEventListener("keydown", closeOnEscape);
window.removeEventListener("resize", closeOnDesktop);
};
}, [menuOpen]);
return (
<nav ref={ref} className="landing-nav">
<div className="flex items-center justify-between max-w-[1180px] h-16 mx-auto px-7 max-[760px]:min-h-[58px] max-[760px]:h-auto max-[760px]:px-[18px] max-[760px]:py-2.5">
<Link href={`/${lang}`} className="flex items-center gap-2.5 text-landing-ink text-2xl font-[820]">
<img src="/logo.png" alt="DBX" width={28} height={28} />
<nav ref={ref} className={`landing-nav${menuOpen ? " is-menu-open" : ""}`} aria-label={lang === "cn" ? "主导航" : "Primary navigation"}>
<div className="landing-nav-inner flex items-center justify-between max-w-[1180px] h-16 mx-auto px-7 max-[760px]:min-h-[60px] max-[760px]:h-auto max-[760px]:px-[18px] max-[760px]:py-2">
<Link href={`/${lang}`} className="landing-nav-brand flex min-h-11 items-center gap-2.5 text-landing-ink text-2xl font-[820]" onClick={() => setMenuOpen(false)}>
<img src="/logo.png" alt="" aria-hidden="true" width={28} height={28} />
<span>DBX</span>
</Link>
<div className="flex items-center gap-1">
<Link href={`/${lang}`} className={`landing-nav-link rounded-[7px] px-[11px] py-2 text-[13px] font-medium max-[760px]:hidden ${active === "home" ? "text-landing-ink" : "text-landing-muted"}`}>
{t.home}
</Link>
<Link href={`/${lang}/docs/what-is-dbx`} className="landing-nav-link rounded-[7px] px-[11px] py-2 text-[13px] font-medium max-[760px]:hidden text-landing-muted">
{t.docs}
</Link>
<Link href={`/${lang}/changelog`} className={`landing-nav-link rounded-[7px] px-[11px] py-2 text-[13px] font-medium max-[760px]:hidden ${active === "changelog" ? "text-landing-ink" : "text-landing-muted"}`}>
{t.changelog}
</Link>
<Link href={`/${lang}/community`} className={`landing-nav-link rounded-[7px] px-[11px] py-2 text-[13px] font-medium max-[760px]:hidden ${active === "community" ? "text-landing-ink" : "text-landing-muted"}`}>
{t.community}
</Link>
<Link href={`/${lang}/sponsors`} className={`landing-nav-link rounded-[7px] px-[11px] py-2 text-[13px] font-medium max-[900px]:hidden ${active === "sponsors" ? "text-landing-ink" : "text-landing-muted"}`}>
{t.sponsors}
</Link>
<Link href={`/${lang}/contributors`} className={`landing-nav-link rounded-[7px] px-[11px] py-2 text-[13px] font-medium max-[900px]:hidden ${active === "contributors" ? "text-landing-ink" : "text-landing-muted"}`}>
{t.contributors}
</Link>
<Link href={`/${lang}/drivers`} className={`landing-nav-link rounded-[7px] px-[11px] py-2 text-[13px] font-medium max-[760px]:hidden ${active === "drivers" ? "text-landing-ink" : "text-landing-muted"}`}>
{t.drivers}
</Link>
<Link href="https://github.com/t8y2/dbx" target="_blank" aria-label="GitHub" title="GitHub" className="landing-nav-link inline-flex size-9 items-center justify-center rounded-[7px] text-landing-muted max-[760px]:hidden">
{navItems.map((item) => (
<Link
key={item.id}
href={item.href}
aria-current={active === item.id ? "page" : undefined}
className={`landing-nav-link inline-flex min-h-11 items-center rounded-[7px] px-[11px] text-[13px] font-medium max-[760px]:hidden ${item.tabletHidden ? "max-[900px]:hidden" : ""} ${active === item.id ? "text-landing-ink" : "text-landing-muted"}`}
>
{item.label}
</Link>
))}
<Link href="https://github.com/t8y2/dbx" target="_blank" rel="noopener noreferrer" aria-label="GitHub" title="GitHub" className="landing-nav-link inline-flex size-11 items-center justify-center rounded-[7px] text-landing-muted max-[760px]:hidden">
<Github size={18} strokeWidth={2} />
</Link>
<Link href={langHref} aria-label={t.langLabel} title={t.langLabel} className="landing-nav-link ml-1.5 inline-flex h-9 items-center justify-center rounded-[7px] border border-landing-line px-2.5 text-[12px] font-[650] tracking-tight text-landing-muted">
<Link href={langHref} aria-label={t.langLabel} title={t.langLabel} className="landing-nav-link ml-1.5 inline-flex min-h-11 items-center justify-center rounded-[7px] border border-landing-line px-3 text-[12px] font-[650] tracking-tight text-landing-muted" onClick={() => setMenuOpen(false)}>
文/A
</Link>
<button
type="button"
className="landing-nav-link ml-1 inline-flex size-11 items-center justify-center rounded-[7px] border border-landing-line text-landing-ink min-[761px]:hidden"
aria-controls="landing-mobile-menu"
aria-expanded={menuOpen}
aria-label={menuOpen ? t.closeMenu : t.menu}
onClick={() => setMenuOpen((current) => !current)}
>
{menuOpen ? <X size={21} /> : <Menu size={21} />}
</button>
</div>
</div>
<div id="landing-mobile-menu" className="landing-mobile-menu min-[761px]:hidden" data-open={menuOpen} aria-hidden={!menuOpen}>
<button type="button" className="landing-mobile-menu-backdrop" aria-label={t.closeMenu} tabIndex={menuOpen ? 0 : -1} onClick={() => setMenuOpen(false)} />
<div className="landing-mobile-menu-panel">
{navItems.map((item) => (
<Link
key={item.id}
href={item.href}
aria-current={active === item.id ? "page" : undefined}
className="landing-mobile-menu-link"
onClick={() => setMenuOpen(false)}
tabIndex={menuOpen ? 0 : -1}
>
<span>{item.label}</span>
<span aria-hidden="true">→</span>
</Link>
))}
<Link href="https://github.com/t8y2/dbx" target="_blank" rel="noopener noreferrer" className="landing-mobile-menu-link" onClick={() => setMenuOpen(false)} tabIndex={menuOpen ? 0 : -1}>
<span className="inline-flex items-center gap-2"><Github size={17} /> GitHub</span>
<span aria-hidden="true">↗</span>
</Link>
</div>
</div>
</nav>
+4 -4
View File
@@ -1,15 +1,15 @@
"use client";
import type { CSSProperties, ReactNode } from "react";
import type { ComponentPropsWithoutRef, CSSProperties, ReactNode } from "react";
import { useEffect, useRef, useState } from "react";
type RevealSectionProps = {
type RevealSectionProps = Omit<ComponentPropsWithoutRef<"section">, "children" | "className"> & {
children: ReactNode;
className?: string;
delay?: number;
};
export function RevealSection({ children, className = "", delay = 0 }: RevealSectionProps) {
export function RevealSection({ children, className = "", delay = 0, ...sectionProps }: RevealSectionProps) {
const ref = useRef<HTMLElement | null>(null);
const [visible, setVisible] = useState(false);
@@ -32,7 +32,7 @@ export function RevealSection({ children, className = "", delay = 0 }: RevealSec
}, []);
return (
<section ref={ref} className={`${className} landing-reveal${visible ? " is-visible" : ""}`} style={{ "--reveal-delay": `${delay}ms` } as CSSProperties}>
<section {...sectionProps} ref={ref} className={`${className} landing-reveal${visible ? " is-visible" : ""}`} style={{ ...sectionProps.style, "--reveal-delay": `${delay}ms` } as CSSProperties}>
{children}
</section>
);