feat: multi-author support, back to top

This commit is contained in:
enscribe 2024-09-12 01:33:52 -07:00
parent 4382f7165c
commit 77bf1bbdf4
No known key found for this signature in database
GPG key ID: 9BBD5C4114E25322
13 changed files with 195 additions and 105 deletions

View file

@ -1,3 +1,4 @@
import { getEntry } from 'astro:content'
import { clsx, type ClassValue } from 'clsx'
import { twMerge } from 'tailwind-merge'
@ -19,3 +20,27 @@ export function readingTime(html: string) {
const readingTimeMinutes = (wordCount / 200 + 1).toFixed()
return `${readingTimeMinutes} min read`
}
export async function parseAuthors(authors: string[]) {
if (!authors || authors.length === 0) return []
const parseAuthor = async (slug: string) => {
try {
const author = await getEntry('authors', slug)
return {
name: author?.data?.name || slug,
avatar: author?.data?.avatar || '/512x512.png',
isRegistered: !!author,
}
} catch (error) {
console.error(`Error fetching author with slug ${slug}:`, error)
return {
name: slug,
avatar: '/512x512.png',
isRegistered: false,
}
}
}
return await Promise.all(authors.map(parseAuthor))
}