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.
This commit is contained in:
1 parent
642551064c
commit
5cbda35e32
50 files changed
+2429
-219
No files matched your search
@@ -0,0 +1,90 @@
|
||||
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) {
|
||||
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;
|
||||
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>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user