forked from emdash-cms/emdash
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentryTitle.ts
More file actions
20 lines (20 loc) · 728 Bytes
/
Copy pathentryTitle.ts
File metadata and controls
20 lines (20 loc) · 728 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/**
* The title to show for a content entry. Uses the collection's `displayField`
* (#1133) if set and non-empty, otherwise falls back to `title → name → slug → id`.
* Shared so every surface (list, picker, editor) shows the same title.
*/
export function getEntryTitle(
item: { data: Record<string, unknown>; slug: string | null; id: string },
displayField?: string,
): string {
const preferred = displayField ? item.data[displayField] : undefined;
const rawTitle = item.data.title;
const rawName = item.data.name;
return (
(typeof preferred === "string" ? preferred : "") ||
(typeof rawTitle === "string" ? rawTitle : "") ||
(typeof rawName === "string" ? rawName : "") ||
item.slug ||
item.id
);
}