Replace the Four Pillars page with the Guide to CommunityRule on the Content page Template.

This commit is contained in:
adilallo committed 2026-11-12 17:57:37 -07:00
1 parent bf9ee79c9f
commit 453139c783
17 files changed
+1005 -32

No files matched your search

@@ -0,0 +1,284 @@
import type { ReactNode } from "react";
import Link from "next/link";
import Button from "../../../components/buttons/Button";
import Rule from "../../../components/cards/Rule";
import type { Category } from "../../../components/cards/Rule";
import type { ChipOption } from "../../../components/controls/MultiSelect/MultiSelect.types";
import {
ASSETS,
getAssetPath,
howItWorksFigureAssetPath,
} from "../../../../lib/assetUtils";
import {
asHowItWorksGuideBlock,
formatHowItWorksByline,
howItWorksReadMinutes,
howItWorksWikiMarkdown,
type HowItWorksGuideBlock,
} from "../../../../lib/howItWorksGuide";
import type howItWorksPage from "../../../../messages/en/pages/howItWorks.json";
import HowItWorksShareRow from "./HowItWorksShareRow";
type HowItWorksMessages = typeof howItWorksPage;
const INLINE_LINK = /\[([^\]]+)\]\(([^)]+)\)/g;
const LINK_CLASS = "underline decoration-solid underline-offset-2";
const ARTICLE_COLUMN_CLASS =
"mx-auto flex w-full flex-col gap-[var(--space-800)] text-[var(--color-content-default-primary)] text-medium-paragraph sm:max-w-[390px] sm:text-large-paragraph md:max-w-[472px] lg:max-w-[700px] lg:text-x-large-paragraph xl:max-w-none xl:text-xx-large-paragraph";
function isSafeHref(href: string): boolean {
return (
href.startsWith("#") ||
(href.startsWith("/") && !href.startsWith("//")) ||
href.startsWith("https://") ||
href.startsWith("http://") ||
href.startsWith("mailto:")
);
}
function GuideInlineText({ text }: { text: string }) {
const nodes: ReactNode[] = [];
let lastIndex = 0;
let key = 0;
for (const match of text.matchAll(INLINE_LINK)) {
const matchIndex = match.index ?? 0;
if (matchIndex > lastIndex) {
nodes.push(text.slice(lastIndex, matchIndex));
}
const label = match[1];
const href = match[2];
if (isSafeHref(href)) {
const isInternal = href.startsWith("/") && !href.startsWith("//");
nodes.push(
isInternal ? (
<Link key={key} href={href} className={LINK_CLASS}>
{label}
</Link>
) : (
<a key={key} href={href} className={LINK_CLASS}>
{label}
</a>
),
);
key += 1;
} else {
nodes.push(label);
}
lastIndex = matchIndex + match[0].length;
}
if (lastIndex < text.length) {
nodes.push(text.slice(lastIndex));
}
return nodes;
}
function chipsFromLabels(labels: string[]): ChipOption[] {
return labels.map((label) => ({
id: label.toLowerCase().replace(/[^a-z0-9]+/g, "-"),
label,
state: "unselected" as const,
}));
}
function teamRuleCategories(
groups: HowItWorksMessages["teamRule"]["categories"],
): Category[] {
return [
groups.values,
groups.communication,
groups.membership,
groups.decisionMaking,
groups.conflictManagement,
].map((group) => ({
name: group.name,
chipOptions: chipsFromLabels(group.chips),
}));
}
function GuideParagraph({
lead,
text,
}: {
lead?: string;
text: string;
}) {
return (
<p>
{lead ? <strong>{lead} </strong> : null}
<GuideInlineText text={text} />
</p>
);
}
function FlowFigure({
src,
caption,
}: {
src: string;
caption: string;
}) {
return (
<figure className="flex w-full flex-col gap-[var(--space-300)]">
<div className="overflow-clip rounded-[var(--radius-400)] border border-[color-mix(in_srgb,var(--color-content-default-primary)_30%,transparent)]">
{/* eslint-disable-next-line @next/next/no-img-element -- flow screen from Figma; one-sentence caption is the accessible name */}
<img
src={getAssetPath(howItWorksFigureAssetPath(src))}
alt=""
width={700}
height={438}
className="h-auto w-full"
/>
</div>
<figcaption className="text-small-paragraph sm:text-medium-paragraph lg:text-large-paragraph">
{caption}
</figcaption>
</figure>
);
}
function TeamRuleFigure({
page,
}: {
page: HowItWorksMessages;
}) {
const { teamRule } = page;
return (
<figure
id="how-it-works-rule-card"
className="flex w-full flex-col gap-[var(--space-300)]"
>
<div className="flex justify-center overflow-clip rounded-[var(--radius-400)] border border-[color-mix(in_srgb,var(--color-content-default-primary)_30%,transparent)] px-[var(--space-400)] py-[var(--space-600)]">
<Rule
title={teamRule.title}
description={teamRule.description}
expanded
size="L"
fluidWidth
interactive={false}
hideCategoryAddButton
descriptionAtBottom
backgroundColor="bg-[var(--color-surface-invert-brand-primary)]"
className="w-full max-w-[400px]"
categories={teamRuleCategories(teamRule.categories)}
icon={
// eslint-disable-next-line @next/next/no-img-element -- decorative brand mark beside the title
<img
src={getAssetPath(ASSETS.LOGO)}
alt=""
width={88}
height={88}
className="size-full object-contain brightness-0"
role="presentation"
/>
}
/>
</div>
<figcaption className="text-small-paragraph sm:text-medium-paragraph lg:text-large-paragraph">
{teamRule.caption}
</figcaption>
</figure>
);
}
function GuideBlockView({
block,
page,
shareUrl,
}: {
block: HowItWorksGuideBlock;
page: HowItWorksMessages;
shareUrl: string;
}) {
if (block.type === "p") {
return <GuideParagraph lead={block.lead} text={block.text} />;
}
if (block.type === "figure") {
return <FlowFigure src={block.src} caption={block.caption} />;
}
if (block.type === "ruleFigure") {
return <TeamRuleFigure page={page} />;
}
const wikiMarkdown = howItWorksWikiMarkdown(
page.banner.title,
page.banner.description,
shareUrl,
);
const mailtoHref = `mailto:?subject=${encodeURIComponent(page.banner.title)}&body=${encodeURIComponent(`${page.banner.title}\n${shareUrl}`)}`;
return (
<HowItWorksShareRow
sendLabel={page.share.send}
copyLabel={page.share.copyWiki}
printLabel={page.share.print}
copiedTitle={page.share.copiedTitle}
copyFailedTitle={page.share.copyFailedTitle}
mailtoHref={mailtoHref}
wikiMarkdown={wikiMarkdown}
/>
);
}
export default function HowItWorksGuideBody({
page,
shareUrl,
}: {
page: HowItWorksMessages;
shareUrl: string;
}) {
const minutes = howItWorksReadMinutes(page);
const byline = formatHowItWorksByline(page, minutes);
return (
<div className={ARTICLE_COLUMN_CLASS}>
<p>
{byline}
<a href="#before-you-start" className={LINK_CLASS}>
{page.byline.beforeYouStart}
</a>
</p>
{page.sections.map((section) => (
<section
key={section.id}
id={section.id}
className="flex w-full flex-col gap-[var(--space-600)]"
>
<h2 className="font-bricolage-grotesque text-large-heading">
{section.heading}
</h2>
{section.blocks.map((block, index) => (
<GuideBlockView
key={`${section.id}-${index}`}
block={asHowItWorksGuideBlock(block)}
page={page}
shareUrl={shareUrl}
/>
))}
</section>
))}
<div className="flex flex-wrap items-start gap-[var(--space-400)]">
<Button
buttonType="filled"
palette="default"
size="medium"
href={page.closing.createRuleHref}
>
{page.closing.createRule}
</Button>
<Button
buttonType="outline"
palette="default"
size="medium"
href={page.closing.downloadKitHref}
>
{page.closing.downloadKit}
</Button>
</div>
</div>
);
}
@@ -0,0 +1,81 @@
"use client";
import { useCallback, useState } from "react";
import Alert from "../../../components/modals/Alert";
import Button from "../../../components/buttons/Button";
type HowItWorksShareRowProps = {
sendLabel: string;
copyLabel: string;
printLabel: string;
copiedTitle: string;
copyFailedTitle: string;
mailtoHref: string;
wikiMarkdown: string;
};
export default function HowItWorksShareRow({
sendLabel,
copyLabel,
printLabel,
copiedTitle,
copyFailedTitle,
mailtoHref,
wikiMarkdown,
}: HowItWorksShareRowProps) {
const [status, setStatus] = useState<"idle" | "copied" | "failed">("idle");
const handleCopy = useCallback(async () => {
try {
await navigator.clipboard.writeText(wikiMarkdown);
setStatus("copied");
} catch {
setStatus("failed");
}
}, [wikiMarkdown]);
const handlePrint = useCallback(() => {
window.print();
}, []);
return (
<div className="flex w-full flex-col gap-[var(--space-400)]">
<div className="flex flex-wrap items-start gap-[var(--space-300)]">
<Button
buttonType="outline"
palette="default"
size="small"
href={mailtoHref}
>
{sendLabel}
</Button>
<Button
buttonType="outline"
palette="default"
size="small"
onClick={handleCopy}
>
{copyLabel}
</Button>
<Button
buttonType="outline"
palette="default"
size="small"
onClick={handlePrint}
>
{printLabel}
</Button>
</div>
{status !== "idle" ? (
<Alert
type="banner"
status={status === "copied" ? "positive" : "danger"}
size="s"
title={status === "copied" ? copiedTitle : copyFailedTitle}
hasBodyText={false}
onClose={() => setStatus("idle")}
/>
) : null}
</div>
);
}
+12 -10
View File
@@ -5,7 +5,7 @@
import type { Metadata } from "next";
import dynamic from "next/dynamic";
import messages from "../../../messages/en/index";
import { getAllBlogPosts } from "../../../lib/content";
import { getRelatedBlogPosts } from "../../../lib/content";
import {
buildHowItWorksSyntheticPost,
HOW_IT_WORKS_SENTINEL_SLUG,
@@ -15,6 +15,7 @@ import { absoluteSiteUrl, routeMetadata } from "../../../lib/siteMetadata";
import ContentBanner from "../../components/sections/ContentBanner";
import ContentTemplateDecorativeShapes from "../_components/ContentTemplateDecorativeShapes";
import AskOrganizer from "../../components/sections/AskOrganizer";
import HowItWorksGuideBody from "./_components/HowItWorksGuideBody";
import "../blog/blog.css";
const RelatedArticles = dynamic(
@@ -48,10 +49,14 @@ export default async function HowItWorksPage() {
const origin = await getRequestSiteOrigin();
const page = messages.pages.howItWorks;
const syntheticPost = buildHowItWorksSyntheticPost(page);
const shareUrl = absoluteSiteUrl("/how-it-works", origin);
const allPosts = getAllBlogPosts();
const relatedPosts = allPosts.slice(0, 8);
const slugOrder = allPosts.map((post) => post.slug);
const relatedPosts = getRelatedBlogPosts(
HOW_IT_WORKS_SENTINEL_SLUG,
page.relatedSlugs,
3,
);
const slugOrder = page.relatedSlugs;
const askOrganizerData = {
title: messages.pages.home.askOrganizer.title,
@@ -64,7 +69,7 @@ export default async function HowItWorksPage() {
"@type": "WebPage",
name: page.banner.title,
description: messages.metadata.howItWorks.description,
url: absoluteSiteUrl("/how-it-works", origin),
url: shareUrl,
publisher: {
"@type": "Organization",
name: "CommunityRule",
@@ -86,7 +91,7 @@ export default async function HowItWorksPage() {
"@type": "ListItem",
position: 2,
name: page.banner.title,
item: absoluteSiteUrl("/how-it-works", origin),
item: shareUrl,
},
],
};
@@ -113,10 +118,7 @@ export default async function HowItWorksPage() {
<ContentTemplateDecorativeShapes variant="guide" />
<article className="relative z-10 p-[var(--space-600)] sm:py-[var(--space-800)] xl:px-[calc(268/1440*100%)]">
<div
className="post-body text-[var(--color-content-default-primary)] text-medium-paragraph sm:text-large-paragraph lg:text-x-large-paragraph xl:text-xx-large-paragraph sm:mx-auto sm:max-w-[390px] md:max-w-[472px] lg:max-w-[700px] xl:max-w-none"
dangerouslySetInnerHTML={{ __html: syntheticPost.htmlContent }}
/>
<HowItWorksGuideBody page={page} shareUrl={shareUrl} />
</article>
</div>