38 lines
965 B
TypeScript
38 lines
965 B
TypeScript
import { BLOG_TEAM_FALLBACK } from './blogDates';
|
|
|
|
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_TEAM_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: teamName, teamName };
|
|
}
|