import type { Metadata } from "next"; import { notFound } from "next/navigation"; import messages from "../../../../messages/en/index"; import { getReadablePublishedRule } from "../../../../lib/server/publishedRules"; import { getSessionUser } from "../../../../lib/server/session"; import { parsePublishedDocumentForCommunityRuleDisplay } from "../../../../lib/create/publishedDocumentToDisplaySections"; import { robotsForPublishedRule, routeMetadata, } from "../../../../lib/siteMetadata"; import CommunityRule from "../../../components/type/CommunityRule"; import HeaderLockup from "../../../components/type/HeaderLockup"; interface PageProps { params: Promise<{ id: string }>; } async function loadReadableRule(id: string) { const user = await getSessionUser(); return getReadablePublishedRule({ idOrSlug: id, user, viaShareSlug: false, requestPath: `/rules/${id}`, }); } export async function generateMetadata({ params, }: PageProps): Promise { const { id } = await params; const resolved = await loadReadableRule(id); if (!resolved) { return { title: messages.pages.ruleDetail.notFoundTitle, description: "The requested CommunityRule could not be found.", }; } const { rule } = resolved; const description = typeof rule.summary === "string" && rule.summary.trim().length > 0 ? rule.summary : undefined; const robots = robotsForPublishedRule(rule.isListed); return routeMetadata(`/rules/${rule.id}`, { title: rule.title, description, ...(robots ? { robots } : {}), openGraph: { title: rule.title, description, type: "article", url: `/rules/${rule.id}`, siteName: messages.metadata.siteName, }, twitter: { card: "summary_large_image", title: rule.title, description, }, }); } export default async function PublicRuleDetailPage({ params }: PageProps) { const { id } = await params; const resolved = await loadReadableRule(id); if (!resolved) { notFound(); } const { rule } = resolved; const sections = parsePublishedDocumentForCommunityRuleDisplay(rule.document); const description = typeof rule.summary === "string" && rule.summary.trim().length > 0 ? rule.summary : undefined; return (
); }