27 lines
696 B
TypeScript
27 lines
696 B
TypeScript
import { getEntry } from 'astro:content'
|
|
|
|
export async function parseAuthors(authors: string[]) {
|
|
if (!authors || authors.length === 0) return []
|
|
|
|
const parseAuthor = async (id: string) => {
|
|
try {
|
|
const author = await getEntry('authors', id)
|
|
return {
|
|
id,
|
|
name: author?.data?.name || id,
|
|
avatar: author?.data?.avatar || '/static/logo.png',
|
|
isRegistered: !!author,
|
|
}
|
|
} catch (error) {
|
|
console.error(`Error fetching author with id ${id}:`, error)
|
|
return {
|
|
id,
|
|
name: id,
|
|
avatar: '/static/logo.png',
|
|
isRegistered: false,
|
|
}
|
|
}
|
|
}
|
|
|
|
return await Promise.all(authors.map(parseAuthor))
|
|
}
|