Show invited people the Rule, let them copy its cards for their community, and replace an expired invitation link.

This commit is contained in:
adilallo committed 2026-11-06 09:16:06 -07:00
1 parent 727a92a9ac
commit 3c984e00c5
37 files changed
+1962 -19

No files matched your search

+59
View File
@@ -0,0 +1,59 @@
import type { CommunityRuleSection } from "../../app/components/type/CommunityRule/CommunityRule.types";
import { parsePublishedDocumentForCommunityRuleDisplay } from "./publishedDocumentToDisplaySections";
const IDENTITY_KEYS = [
"communityAvatarUrl",
"communityAvatarFileName",
"communityContext",
"communityLocation",
"communitySaveEmail",
"title",
] as const;
export type CopiedNameHit = {
categoryName: string;
entryTitle: string;
};
/** Copy cards and text; drop name, description, photo, and save-email. */
export function stripCopiedRuleDocument(
document: unknown,
): Record<string, unknown> {
if (!document || typeof document !== "object" || Array.isArray(document)) {
return {};
}
const copy = structuredClone(document) as Record<string, unknown>;
for (const key of IDENTITY_KEYS) {
delete copy[key];
}
return copy;
}
function entryHaystack(entry: CommunityRuleSection["entries"][number]): string {
const blockText = (entry.blocks ?? [])
.map((block) => `${block.label} ${block.body}`)
.join("\n");
return `${entry.title}\n${entry.body}\n${blockText}`;
}
/** First line that still names the original community after a copy. */
export function findCopiedNameHit(
document: unknown,
originalName: string,
): CopiedNameHit | null {
const name = originalName.trim();
if (name.length < 2) return null;
const needle = name.toLowerCase();
const sections = parsePublishedDocumentForCommunityRuleDisplay(document);
for (const section of sections) {
for (const entry of section.entries) {
if (entryHaystack(entry).toLowerCase().includes(needle)) {
return {
categoryName: section.categoryName,
entryTitle: entry.title,
};
}
}
}
return null;
}