import { useEffect, useState } from 'react' import { getPagesUnderRoute } from 'nextra/context' import { type Page } from 'nextra' import { SocialIcon } from 'react-social-icons' import BlogCard from '../blog/BlogCard' import Image from 'next/image' import { Cards } from 'nextra/components' import { OurAuthors, Blog } from '@/components/CardIcons' // Known issues: // - Mobile: social icons overflow when author has more than 4 social links // - SocialIcon uses the generic "share" icon when the platform is unrecognized // - "Recent Posts by" section does not support filtering by tag // - Profile image positioning is off when the author has no bio text interface AuthorMetadata { authorid: string subtitle: string name: string bio: string ogImage: string socials?: Record // Dynamically match social media platforms date: string | number | Date } interface AuthorProfileProps { authorId: string } const AuthorProfile: React.FC = ({ authorId }) => { const authors = getPagesUnderRoute('/authors') as Array const author = authors.find((a) => a.frontMatter.authorid === authorId)?.frontMatter const blogPosts = getPagesUnderRoute('/blog') as Array // Filter posts by the current authorId const authorPosts = blogPosts.filter((post) => post.frontMatter.authorid === authorId) const sortedAuthorPosts = authorPosts.sort( (a, b) => new Date(b.frontMatter.date).getTime() - new Date(a.frontMatter.date).getTime(), ) // State to track whether the component is rendered on the client side const [isClient, setIsClient] = useState(false) useEffect(() => { setIsClient(true) }, []) if (!author) { return
Author not found!
} const socialsEntries = Object.entries(author.socials ?? {}).filter(([, value]) => !!value) return ( <>

{author.name}

{author.subtitle}

{author.bio &&

{author.bio}

}
{author.name}
{isClient && socialsEntries.map(([key, value]) => ( ))}

Recent Posts by {author.name}

{sortedAuthorPosts.map((post) => ( {}} selectedTags={undefined} /> ))}
} image> {null} } image> {null}
) } export default AuthorProfile