40 lines
1.0 KiB
TypeScript
40 lines
1.0 KiB
TypeScript
import { BLOG_TEAM_FALLBACK } from './blogDates';
|
|
|
|
export const BLOG_AUTHOR_FALLBACK = 'کنینا';
|
|
|
|
type BlogAuthor = {
|
|
firstName?: string | null;
|
|
lastName?: string | null;
|
|
};
|
|
|
|
interface BlogAuthorInput {
|
|
author?: BlogAuthor | null;
|
|
authorTeam?: string | null;
|
|
}
|
|
|
|
export interface ResolvedBlogAuthor {
|
|
type: 'Person' | 'Organization';
|
|
name: string;
|
|
teamName: string;
|
|
}
|
|
|
|
export function resolveBlogAuthor(author?: BlogAuthor | null): string {
|
|
const name = author
|
|
? `${author.firstName || ''} ${author.lastName || ''}`.trim()
|
|
: '';
|
|
return name || BLOG_AUTHOR_FALLBACK;
|
|
}
|
|
|
|
export function resolveBlogAuthorIdentity(blog: BlogAuthorInput): ResolvedBlogAuthor {
|
|
const personName = blog.author
|
|
? `${blog.author.firstName || ''} ${blog.author.lastName || ''}`.trim()
|
|
: '';
|
|
const teamName = blog.authorTeam?.trim() || BLOG_TEAM_FALLBACK;
|
|
|
|
if (personName) {
|
|
return { type: 'Person', name: personName, teamName };
|
|
}
|
|
|
|
return { type: 'Organization', name: BLOG_AUTHOR_FALLBACK, teamName };
|
|
}
|