Use specific kind labels in embed cards instead of parent category name

Add getKindLabel() to extraKinds.ts as the canonical resolver for
per-kind labels. Kinds in extraFeedKinds (like nsites 15128/35128)
now show 'nsite' instead of the parent category 'development'.
This commit is contained in:
Alex Gleason
2026-03-24 20:57:20 -05:00
parent d94ff90bc7
commit a8cb7240bf
3 changed files with 43 additions and 15 deletions
+5 -8
View File
@@ -12,7 +12,7 @@ import { useAuthor } from '@/hooks/useAuthor';
import { genUserName } from '@/lib/genUserName';
import { timeAgo } from '@/lib/timeAgo';
import { cn } from '@/lib/utils';
import { EXTRA_KINDS, getKindIcon } from '@/lib/extraKinds';
import { getKindLabel, getKindIcon } from '@/lib/extraKinds';
import type { NostrEvent } from '@nostrify/nostrify';
interface EmbeddedNaddrProps {
@@ -191,14 +191,11 @@ function EmbeddedNaddrCard({ event, className }: { event: NostrEvent; className?
return description.slice(0, MAX_CONTENT_LENGTH).trimEnd() + '…';
}, [description]);
// Kind label for context (e.g. "development" with icon)
// Kind label for context (e.g. "nsite" with icon)
const kindMeta = useMemo(() => {
const kindDef = EXTRA_KINDS.find((def) =>
def.subKinds?.some((sub) => sub.kind === event.kind) || def.kind === event.kind
|| def.extraFeedKinds?.includes(event.kind),
);
if (!kindDef) return undefined;
return { label: kindDef.label.toLowerCase(), Icon: getKindIcon(event.kind) };
const label = getKindLabel(event.kind);
if (!label) return undefined;
return { label, Icon: getKindIcon(event.kind) };
}, [event.kind]);
return (
+3 -7
View File
@@ -16,7 +16,7 @@ import { timeAgo } from '@/lib/timeAgo';
import { cn } from '@/lib/utils';
import { useAppContext } from '@/hooks/useAppContext';
import { IMAGE_URL_REGEX, IMETA_MEDIA_URL_REGEX, extractVideoUrls, extractAudioUrls } from '@/lib/mediaUrls';
import { EXTRA_KINDS, getKindIcon } from '@/lib/extraKinds';
import { getKindLabel, getKindIcon } from '@/lib/extraKinds';
/** NIP-62 Request to Vanish. */
const VANISH_KIND = 62;
@@ -144,12 +144,8 @@ function EmbeddedNoteCard({
const title = getTag('title') || getTag('name') || getTag('d');
const description = getTag('summary') || getTag('description');
// Build a kind label line for context (e.g. "nsite · 31 files")
const kindDef = EXTRA_KINDS.find((def) =>
def.subKinds?.some((sub) => sub.kind === event.kind) || def.kind === event.kind
|| def.extraFeedKinds?.includes(event.kind),
);
const kindLabel = kindDef?.label.toLowerCase();
// Build a kind label line for context (e.g. "nsite")
const kindLabel = getKindLabel(event.kind);
const KindIcon = getKindIcon(event.kind);
if (!title && !description && !kindLabel) return undefined;
+35
View File
@@ -513,6 +513,41 @@ export function getPageKinds(def: ExtraKindDef, feedSettings: FeedSettings): num
.map((sub) => sub.kind);
}
/**
* Specific labels for kinds that don't have their own top-level ExtraKindDef.
* These are kinds buried in `extraFeedKinds` arrays or otherwise needing
* a label more specific than their parent category.
*/
const KIND_SPECIFIC_LABELS: Record<number, string> = {
7: 'reaction',
1617: 'patch',
1618: 'patch comment',
15128: 'nsite',
35128: 'nsite',
30817: 'repository issue',
32267: 'app',
30063: 'release',
};
/**
* Get a human-readable label for a specific kind number.
* Resolution order: subKind label → KIND_SPECIFIC_LABELS → direct def label.
* Returns undefined if the kind is completely unknown.
*/
export function getKindLabel(kind: number): string | undefined {
// Check subKinds first (they carry their own label)
for (const def of EXTRA_KINDS) {
const sub = def.subKinds?.find((s) => s.kind === kind);
if (sub) return sub.label.toLowerCase();
}
// Check specific overrides (extraFeedKinds items, etc.)
if (KIND_SPECIFIC_LABELS[kind]) return KIND_SPECIFIC_LABELS[kind];
// Check top-level def
const def = EXTRA_KINDS.find((d) => d.kind === kind);
if (def) return def.label.toLowerCase();
return undefined;
}
/** Map from kind number to ExtraKindDef id, for quick icon lookup. */
const KIND_TO_ID = new Map<number, string>();
for (const def of EXTRA_KINDS) {