import blogAuthors from 'lib/authors.json' import Image from 'next/image' import Link from 'next/link' import React from 'react' import type PostTypes from '~/types/post' import dayjs from 'dayjs' import { Badge } from 'ui' import type { CMSPostTypes } from '~/types/post' interface Props { post: PostTypes | CMSPostTypes } const getAuthors = (post: PostTypes | CMSPostTypes) => { if ('isCMS' in post && post.isCMS) { // For CMS posts, display author directly from the blog data const cmsBlog = post as CMSPostTypes const authors = cmsBlog.authors?.map((author) => ({ author: author.author || 'Unknown Author', author_image_url: author.author_image_url || null, author_url: author.author_url || '#', position: author.position || '', })) || [] return authors } const authorArray = post.author?.split(',').map((a) => a.trim()) || [] const authors = [] for (let i = 0; i < authorArray.length; i++) { const foundAuthor = blogAuthors.find((authors: any) => { return authors.author_id === authorArray[i] }) if (foundAuthor) { authors.push(foundAuthor) } } return authors } const BlogListItem = ({ post }: Props) => { const authors = getAuthors(post) const sanitizeCategory = (category: string) => category.replaceAll('-', ' ') return (

{post.title}

{authors.map((author: any, i: number) => { if (!author) return null return (
{author.author_image_url && ( {`${author.author} )}
) })}
{post.categories && (
{post.categories.map( (category, i) => i === 0 && ( {sanitizeCategory(category)} ) )}
)} {post.date && (

{dayjs(post.date).format('D MMM YYYY')}

)}
) } export default BlogListItem