feat: multi-author support, back to top
This commit is contained in:
parent
4382f7165c
commit
77bf1bbdf4
13 changed files with 195 additions and 105 deletions
|
@ -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))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue