85 lines
2.9 KiB
TypeScript
85 lines
2.9 KiB
TypeScript
import { getTranslations } from "next-intl/server";
|
|
import Link from "next/link";
|
|
import { ContentCard, EmptyState } from "@/components/public/ui";
|
|
import { excerpt } from "@/lib/format";
|
|
import { prisma } from "@/lib/prisma";
|
|
|
|
export const revalidate = 300;
|
|
|
|
export const metadata = { title: "News" };
|
|
|
|
function formatDate(d: Date | null): string {
|
|
return d ? d.toISOString().slice(0, 10) : "";
|
|
}
|
|
|
|
export default async function NewsPage() {
|
|
const t = await getTranslations("pages.news");
|
|
|
|
let articles: Awaited<ReturnType<typeof prisma.websiteArticles.findMany>> = [];
|
|
try {
|
|
articles = await prisma.websiteArticles.findMany({
|
|
orderBy: { createdAt: "desc" },
|
|
take: 30,
|
|
});
|
|
} catch {
|
|
// DB unavailable — render the empty state rather than a 500.
|
|
articles = [];
|
|
}
|
|
|
|
return (
|
|
<main style={{ display: "grid", gap: "1.5rem" }}>
|
|
<ContentCard
|
|
icon="📰"
|
|
title={t("title")}
|
|
subtitle={t("subtitle")}
|
|
/>
|
|
|
|
<ContentCard padded={articles.length === 0}>
|
|
{articles.length === 0 ? (
|
|
<EmptyState icon="📰">{t("noArticles")}</EmptyState>
|
|
) : (
|
|
<div className="card-grid sm-2 lg-3" style={{ padding: "1rem" }}>
|
|
{articles.map((a) => (
|
|
<Link
|
|
key={a.slug}
|
|
href={`/news/${a.slug}`}
|
|
className="card hover"
|
|
style={{ display: "flex", flexDirection: "column", textDecoration: "none" }}
|
|
>
|
|
<div
|
|
style={{
|
|
background: "linear-gradient(135deg, color-mix(in srgb, var(--color-primary) 10%, var(--color-navbar)), color-mix(in srgb, var(--color-primary) 5%, var(--color-navbar)))",
|
|
borderBottom: "1px solid color-mix(in srgb, var(--color-text-muted) 8%, transparent)",
|
|
padding: "0.6rem 0.75rem",
|
|
fontSize: "0.78rem",
|
|
color: "var(--color-text-muted)",
|
|
}}
|
|
>
|
|
📰 {t("title")} · {formatDate(a.createdAt)}
|
|
</div>
|
|
{a.image ? (
|
|
<img
|
|
src={a.image}
|
|
alt=""
|
|
style={{ width: "100%", aspectRatio: "16/9", objectFit: "cover" }}
|
|
/>
|
|
) : (
|
|
<div
|
|
style={{ width: "100%", aspectRatio: "16/9", backgroundColor: "var(--color-navbar)" }}
|
|
/>
|
|
)}
|
|
<div style={{ padding: "0.75rem" }}>
|
|
<h3 style={{ margin: "0 0 0.25rem", fontSize: "1rem", color: "var(--color-text)" }}>
|
|
{a.title}
|
|
</h3>
|
|
<p style={{ margin: 0, color: "var(--color-text)" }}>{excerpt(a.shortStory, 200)}</p>
|
|
</div>
|
|
</Link>
|
|
))}
|
|
</div>
|
|
)}
|
|
</ContentCard>
|
|
</main>
|
|
);
|
|
}
|