90 lines
2.8 KiB
TypeScript
90 lines
2.8 KiB
TypeScript
import type { Metadata } from "next";
|
|
import { notFound } from "next/navigation";
|
|
import { connection } from "next/server";
|
|
import { getPublicConfig } from "@/api/config";
|
|
import AboutPageClient from "@/components/about/AboutPageClient";
|
|
import { aboutProfile } from "@/mock/about";
|
|
|
|
export async function generateMetadata(): Promise<Metadata> {
|
|
let title = "春风不解别离意,今日方知我是春。";
|
|
let authorName = "RRTiamo";
|
|
try {
|
|
const response = await getPublicConfig();
|
|
const configs = response.data?.data;
|
|
if (Array.isArray(configs)) {
|
|
const titleConfig = configs.find(
|
|
(item: { configKey?: string; configValue?: string }) =>
|
|
item.configKey === "site.title.about"
|
|
);
|
|
if (titleConfig?.configValue) {
|
|
title = titleConfig.configValue;
|
|
}
|
|
// 作者名取自身份档案聚合键(about_* 关系表拼装),缺失时回退默认值
|
|
const profileConfig = configs.find(
|
|
(item: { configKey?: string; configValue?: string }) =>
|
|
item.configKey === "page.about.profile"
|
|
);
|
|
if (profileConfig?.configValue) {
|
|
try {
|
|
const profile = JSON.parse(profileConfig.configValue);
|
|
if (profile?.name) authorName = profile.name;
|
|
} catch {
|
|
// blob 解析失败时保持默认名
|
|
}
|
|
}
|
|
}
|
|
} catch (error) {
|
|
console.warn("Failed to generate About page metadata:", error);
|
|
}
|
|
|
|
return {
|
|
title,
|
|
description: `我在代码、文字和生活的缝隙里,慢慢搭建一个属于自己的小宇宙。关于 ${authorName},此间主人。`,
|
|
};
|
|
}
|
|
|
|
async function isAboutPageEnabled() {
|
|
try {
|
|
const response = await getPublicConfig();
|
|
const configs = response.data?.data;
|
|
|
|
if (!Array.isArray(configs)) return true;
|
|
|
|
const aboutConfig = configs.find(
|
|
(item: { configKey?: string; configValue?: string }) =>
|
|
item.configKey === "page.about.enable"
|
|
);
|
|
|
|
return aboutConfig?.configValue !== "false";
|
|
} catch (error) {
|
|
console.warn("About page: public config unavailable, keeping page enabled.", error);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
export default async function AboutPage() {
|
|
await connection();
|
|
const enabled = await isAboutPageEnabled();
|
|
|
|
if (!enabled) notFound();
|
|
|
|
let profile = aboutProfile;
|
|
try {
|
|
const response = await getPublicConfig();
|
|
const configs = response.data?.data;
|
|
if (Array.isArray(configs)) {
|
|
const profileConfig = configs.find(
|
|
(item: { configKey?: string; configValue?: string }) =>
|
|
item.configKey === "page.about.profile"
|
|
);
|
|
if (profileConfig?.configValue) {
|
|
profile = JSON.parse(profileConfig.configValue);
|
|
}
|
|
}
|
|
} catch (error) {
|
|
console.warn("Failed to load dynamic about profile, using default fallback.", error);
|
|
}
|
|
|
|
return <AboutPageClient profile={profile} />;
|
|
}
|