feat: render CMS content fields and footer settings
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import Image from "next/image";
|
||||
import { getColumnPage } from "@/services/page.service";
|
||||
|
||||
export async function ColumnHeading({ type, slug, fallback }: { type: string; slug: string; fallback: string }) {
|
||||
const page = await getColumnPage(type, slug).catch(() => null);
|
||||
return (
|
||||
<header className="mb-12">
|
||||
<h1 className="break-words text-4xl font-bold text-slate-900">{page?.title || fallback}</h1>
|
||||
{page?.intro && <p className="mt-4 whitespace-pre-line break-words text-lg leading-relaxed text-slate-600">{page.intro}</p>}
|
||||
</header>
|
||||
);
|
||||
}
|
||||
|
||||
export function PageCover({ image, compact = false }: { image?: { url: string; title: string } | null; compact?: boolean }) {
|
||||
if (!image?.url) return null;
|
||||
return (
|
||||
<div className={`relative mt-4 mb-6 w-full ${compact ? "h-48 sm:h-64" : "aspect-[16/10]"}`}>
|
||||
<Image src={image.url} alt={image.title || ""} fill sizes="(max-width: 768px) 100vw, 896px" className="object-contain" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function PublicationDate({ value }: { value?: string }) {
|
||||
if (!value) return null;
|
||||
const date = new Date(value);
|
||||
if (Number.isNaN(date.getTime())) return null;
|
||||
return <time dateTime={value} className="mt-2 block text-sm text-slate-500">{new Intl.DateTimeFormat("zh-CN", { timeZone: "Asia/Shanghai", year: "numeric", month: "long", day: "numeric" }).format(date)}</time>;
|
||||
}
|
||||
|
||||
export function BlogTags({ tags }: { tags?: string[] }) {
|
||||
if (!tags?.length) return null;
|
||||
return <ul aria-label="文章标签" className="mt-3 flex flex-wrap gap-x-4 gap-y-1 text-sm text-slate-500">{tags.map((tag) => <li key={tag} className="break-all">#{tag}</li>)}</ul>;
|
||||
}
|
||||
Reference in New Issue
Block a user