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:
adilallo committed 2026-11-09 19:54:04 -07:00
1 parent 642551064c
commit 5cbda35e32
50 files changed
+2429 -219

No files matched your search

+56
View File
@@ -0,0 +1,56 @@
import { RULE_VISIBILITY, type RuleVisibility } from "./ruleVisibility";
const SHARE_SLUG_RE = /^[a-z0-9]{4}-[a-z0-9]{4}$/;
export function isShareSlug(value: string): boolean {
return SHARE_SLUG_RE.test(value);
}
export function publishedRulePath(ruleId: string): string {
return `/rules/${encodeURIComponent(ruleId)}`;
}
export function shareRulePath(shareSlug: string): string {
return `/r/${encodeURIComponent(shareSlug)}`;
}
export function buildPublicRuleUrl(origin: string, ruleId: string): string {
const base = origin.replace(/\/$/, "");
return `${base}${publishedRulePath(ruleId)}`;
}
export function buildShareRuleUrl(origin: string, shareSlug: string): string {
const base = origin.replace(/\/$/, "");
return `${base}${shareRulePath(shareSlug)}`;
}
/** Host + path as drawn in the Share control, e.g. `communityrule.info/r/k7f2-9qxm`. */
export function formatShareUrlDisplay(origin: string, shareSlug: string): string {
try {
return `${new URL(origin).host}/r/${shareSlug}`;
} catch {
const host = origin.replace(/^https?:\/\//, "").replace(/\/$/, "");
return `${host}/r/${shareSlug}`;
}
}
/**
* URL the Share control copies and shows.
* Shared-by-link (and featured rows that still have a slug) use `/r/{slug}`.
* Featured without a slug uses `/rules/{id}`. Private uses `/rules/{id}`.
*/
export function shareCopyUrl(opts: {
origin: string;
ruleId: string;
shareSlug: string | null;
visibility: RuleVisibility;
}): string {
if (
opts.shareSlug &&
(opts.visibility === RULE_VISIBILITY.shared_by_link ||
opts.visibility === RULE_VISIBILITY.public_and_featured)
) {
return buildShareRuleUrl(opts.origin, opts.shareSlug);
}
return buildPublicRuleUrl(opts.origin, opts.ruleId);
}