Files
Mebbling/lib/display.ts
T

18 lines
640 B
TypeScript
Raw Normal View History

2026-07-19 13:35:20 +08:00
export type AuthorDisplay = {
origin: string;
username: string;
name: string | null;
remote_user?: string | null;
2026-07-19 13:35:20 +08:00
remote_display_name?: string | null;
source_base_url: string | null;
};
export function postAuthorLabel(post: AuthorDisplay) {
const remoteUser = post.remote_user?.split("/").filter(Boolean).at(-1);
const author = remoteUser || (post.origin === "rss" ? post.name : post.username) || post.name || "unknown";
if (post.source_base_url) {
2026-07-19 13:35:20 +08:00
try { return `@${author}@${new URL(post.source_base_url).hostname}`; } catch { /* Keep a readable fallback for legacy malformed URLs. */ }
}
return `@${author}`;
2026-07-19 13:35:20 +08:00
}