Files
emdash-patch-imageupload/packages/plugins/atproto/src/content.ts
kunthawat 2d1be52177 Emdash source with visual editor image upload fix
Fixes:
1. media.ts: wrap placeholder generation in try-catch
2. toolbar.ts: check r.ok, display error message in popover
2026-05-03 10:44:54 +07:00

37 lines
1.1 KiB
TypeScript

/**
* Shared content helpers for ATProto outputs.
*
* These helpers intentionally stay small and boring so standard.site and
* Bluesky can share path/field lookup behavior without coupling their
* output-specific formatting logic.
*/
export function getString(obj: Record<string, unknown>, key: string): string | undefined {
const value = obj[key];
return typeof value === "string" && value.length > 0 ? value : undefined;
}
export function getContentData(content: Record<string, unknown>): Record<string, unknown> {
return content.data && typeof content.data === "object"
? (content.data as Record<string, unknown>)
: {};
}
export function getContentString(
content: Record<string, unknown>,
key: string,
): string | undefined {
return getString(content, key) || getString(getContentData(content), key);
}
export function buildContentPath(
collection: string | undefined,
content: Record<string, unknown>,
): string | undefined {
const slug = getContentString(content, "slug");
if (!slug) return undefined;
if (!collection || collection === "pages") return `/${slug}`;
return `/${collection}/${slug}`;
}