Filled avatars used white ink on yellow, the link field was a dimmed disabled input, and Copy failed silently when the clipboard API was denied.
88 lines
2.7 KiB
TypeScript
88 lines
2.7 KiB
TypeScript
import type { Metadata } from "next";
|
|
import { notFound } from "next/navigation";
|
|
import messages from "../../../../messages/en/index";
|
|
import { isShareSlug } from "../../../../lib/sharePaths";
|
|
import { getReadablePublishedRule } from "../../../../lib/server/publishedRules";
|
|
import { getSessionUser } from "../../../../lib/server/session";
|
|
import { parsePublishedDocumentForCommunityRuleDisplay } from "../../../../lib/create/publishedDocumentToDisplaySections";
|
|
import { NO_INDEX_ROBOTS, routeMetadata } from "../../../../lib/siteMetadata";
|
|
import CommunityRule from "../../../components/type/CommunityRule";
|
|
import HeaderLockup from "../../../components/type/HeaderLockup";
|
|
|
|
interface PageProps {
|
|
params: Promise<{ shareSlug: string }>;
|
|
}
|
|
|
|
async function loadSharedRule(shareSlug: string) {
|
|
if (!isShareSlug(shareSlug)) return null;
|
|
const user = await getSessionUser();
|
|
return getReadablePublishedRule({
|
|
idOrSlug: shareSlug,
|
|
user,
|
|
viaShareSlug: true,
|
|
requestPath: `/r/${shareSlug}`,
|
|
});
|
|
}
|
|
|
|
export async function generateMetadata({
|
|
params,
|
|
}: PageProps): Promise<Metadata> {
|
|
const { shareSlug } = await params;
|
|
const resolved = await loadSharedRule(shareSlug);
|
|
if (!resolved) {
|
|
notFound();
|
|
}
|
|
const { rule } = resolved;
|
|
const description =
|
|
typeof rule.summary === "string" && rule.summary.trim().length > 0
|
|
? rule.summary
|
|
: undefined;
|
|
return routeMetadata(`/r/${shareSlug}`, {
|
|
title: rule.title,
|
|
description,
|
|
robots: NO_INDEX_ROBOTS,
|
|
openGraph: {
|
|
title: rule.title,
|
|
description,
|
|
type: "article",
|
|
url: `/r/${shareSlug}`,
|
|
siteName: messages.metadata.siteName,
|
|
},
|
|
twitter: {
|
|
card: "summary_large_image",
|
|
title: rule.title,
|
|
description,
|
|
},
|
|
});
|
|
}
|
|
|
|
export default async function SharedRuleDetailPage({ params }: PageProps) {
|
|
const { shareSlug } = await params;
|
|
const resolved = await loadSharedRule(shareSlug);
|
|
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>
|
|
);
|
|
}
|