import type { Metadata } from "next";
import { WORK_ARTICLES } from "@/content/workArticles";
import { isPasscodeProtectedPath } from "@/lib/passcode";
import { getPasscodeAccessServer } from "@/lib/passcodeServer";
import { getSiteConfig, listWorks } from "@/lib/siteConfig";
import { absoluteUrl } from "@/lib/siteUrl";
/**
* Per-page
: the original detail route sets to the work name
* (haoqi.design/reunimos → "Reunimos™"). The protected /2026 is gated on the
* server — without the access cookie its SSR title is "Protected"; once
* unlocked the server renders the article. We mirror both states.
*
* SEO 增强:优先静态 WORK_ARTICLES,其次后台添加的作品(works 表),
* 生成 title / description / canonical / OG。
*/
export async function generateMetadata({
params,
}: {
params: Promise<{ slug: string }>;
}): Promise {
const { slug } = await params;
const path = `/${slug}`;
if (isPasscodeProtectedPath(path)) {
const access = await getPasscodeAccessServer();
if (!access[path]) return { title: "受保护内容", robots: { index: false } };
}
const config = getSiteConfig();
const article = WORK_ARTICLES[path];
if (article) {
return {
title: article.title,
description: article.year || config.site_description,
alternates: { canonical: `/work/${slug}` },
openGraph: {
title: article.title,
type: "article",
url: absoluteUrl(`/work/${slug}`),
images: ["/og.png"],
},
};
}
// 后台添加的作品:works 表有文章字段则使用,否则只给基础元信息。
const row = listWorks(true).find((w) => w.slug === slug);
if (row) {
const desc =
row.article_markdown.trim().slice(0, 160) ||
`${row.name}${row.year ? `(${row.year})` : ""} — ${config.brand_name} 的作品。`;
return {
title: row.name,
description: desc,
alternates: { canonical: `/work/${slug}` },
openGraph: {
title: row.name,
description: desc,
type: "article",
url: absoluteUrl(`/work/${slug}`),
images: row.image_url ? [row.image_url] : ["/og.png"],
},
};
}
return { title: config.site_title, robots: { index: false } };
}
export default function WorkLayout({
children,
}: Readonly<{ children: React.ReactNode }>) {
return children;
}