Files
community-rule/app/(marketing)/rules/[id]/page.tsx
T
adilallo 5cbda35e32 Start every Rule private, with a rotating link and files that follow its readers.
New Rules stay off lists until the person who holds the pen turns on a share link, or the team features one. Uploaded files are readable only by those readers, stripped of location metadata, and deleted with the Rule, draft, or account.
2026-11-09 19:54:04 -07:00

93 lines
2.7 KiB
TypeScript

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<Metadata> {
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 (
<article className="min-h-screen bg-[var(--color-teal-teal50,#c9fef9)]">
<div className="mx-auto flex max-w-[1200px] flex-col gap-[var(--space-1200)] px-5 py-[var(--space-1200)] md:px-12 md:py-[var(--space-1800)]">
<HeaderLockup
title={rule.title}
description={description}
justification="left"
size="L"
palette="inverse"
/>
<CommunityRule sections={sections} />
</div>
</article>
);
}