import Link from "next/link"; import type { Locale } from "@/lib/i18n/config"; import { FACTS } from "@/lib/facts.generated"; import { fetchRepoStats, formatStars } from "@/lib/github"; import { getEnv } from "@/lib/kv"; import { Seal } from "./seal"; import { Whale } from "./whale"; import { LocaleSwitcher } from "./locale-switcher"; import { MobileMenu } from "./mobile-menu"; import { NavLinks } from "./nav-links"; import { ThemeToggle } from "./theme-toggle"; const EN_LINKS = [ { href: "/en/install", label: "Install", cn: "安装" }, { href: "/en/constitution", label: "Constitution", cn: "宪法" }, { href: "/en/docs", label: "Docs", cn: "文档" }, { href: "/en/community", label: "Community", cn: "社区" }, { href: "/en/faq", label: "FAQ", cn: "问答" }, ]; const ZH_LINKS = [ { href: "/zh/install", label: "安装", cn: "" }, { href: "/zh/constitution", label: "宪法", cn: "" }, { href: "/zh/docs", label: "文档", cn: "" }, { href: "/zh/community", label: "社区", cn: "" }, { href: "/zh/faq", label: "常见问题", cn: "" }, ]; export async function Nav({ locale = "en" }: { locale?: Locale }) { const isZh = locale === "zh"; const links = isZh ? ZH_LINKS : EN_LINKS; // Live star count — cached by fetchRepoStats (next.revalidate). Falls back // to a plain "GitHub" label when the API is unreachable at build time. let stars = 0; try { const env = await getEnv(); stars = (await fetchRepoStats(env.GITHUB_TOKEN)).stars; } catch { /* keep fallback label */ } return (
{/* date / build strip */}
{isZh ? `第 ${new Date().toISOString().slice(0, 10)} 期` : `Issue ${new Date().toISOString().slice(0, 10)}`} · {isZh ? new Date().toLocaleDateString("zh-CN", { weekday: "long", month: "long", day: "numeric" }) : new Date().toLocaleDateString("en-US", { weekday: "long", month: "long", day: "numeric" })}
codewhale.net {FACTS.version ? `v${FACTS.version}` : "v0.8.x"}
{/* main nav */}
CodeWhale
{isZh ? "任何模型 · 开源模型优先" : "any model, open models first"}
★ {stars > 0 ? formatStars(stars) : "GitHub"} {isZh ? "安装 →" : "Install →"} ({ href: l.href, label: l.label, cn: !isZh && "cn" in l ? l.cn : undefined, }))} />
); }