---
import { getImage } from "astro:assets"
import { formatDate } from "../helper"
type Post = {
content: string
url: string
created_at: string
media_attachments: {
id: string
preview_url: string
description: string
}[]
emojis: {
shortcode: string
url: string
}[]
}
const posts: Post[] = await (
await fetch(
"https://mastodon.social/api/v1/accounts/112282328572683277/statuses?exclude_replies=true&limit=5",
)
).json()
const attachments = await Promise.all(
posts.map(async (post) => {
if (post.media_attachments.length == 0) return null
return await getImage({
src: post.media_attachments[0].preview_url,
inferSize: true,
})
}),
)
const emojis = await Promise.all(
posts
.flatMap((post) => post.emojis)
.map(async (emoji) => {
return {
shortcode: emoji.shortcode,
...(await getImage({
src: emoji.url,
inferSize: true,
})),
}
}),
)
function replaceEmojis(content: string) {
for (const emoji of emojis) {
content = content.replaceAll(
`:${emoji.shortcode}:`,
``,
)
}
return content
}
---
{
posts.map((post, i) => (