diff options
| author | Dawid Rycerz <dawid@rycerz.xyz> | 2026-01-12 19:54:27 +0100 |
|---|---|---|
| committer | Dawid Rycerz <dawid@rycerz.xyz> | 2026-01-12 19:54:27 +0100 |
| commit | 6e19444bd32c271b53971eaad7377e340259100c (patch) | |
| tree | beed4bdb0bf8aba654c6d8bdadfe09fdc030cf6d | |
| parent | 5e7ea1523908774c7e2dbfd47f0c6e0a2f503971 (diff) | |
Add alt text support
| -rw-r--r-- | src/components/note/Note.astro | 4 | ||||
| -rw-r--r-- | src/content.config.ts | 1 | ||||
| -rw-r--r-- | src/loaders/pleroma.ts | 1 | ||||
| -rw-r--r-- | src/pages/micro/rss.xml.ts | 4 |
4 files changed, 6 insertions, 4 deletions
diff --git a/src/components/note/Note.astro b/src/components/note/Note.astro index 3017d2d..920cbc1 100644 --- a/src/components/note/Note.astro +++ b/src/components/note/Note.astro @@ -47,7 +47,7 @@ const { Content } = await render(note); { !isPreview && note.data.attachments && note.data.attachments.length > 0 && ( <div class="mt-6 grid grid-cols-1 gap-4 sm:grid-cols-2"> - {note.data.attachments.map((attachment: { url: string; type: string }) => ( + {note.data.attachments.map((attachment: { type: string; url: string; alt?: string }) => ( <a href={attachment.url} target="_blank" @@ -56,7 +56,7 @@ const { Content } = await render(note); > <img src={attachment.url} - alt="Attachment" + alt={attachment.alt || "Image"} class="h-48 w-full object-cover" loading="lazy" /> diff --git a/src/content.config.ts b/src/content.config.ts index 2ae9fbf..032011e 100644 --- a/src/content.config.ts +++ b/src/content.config.ts @@ -53,6 +53,7 @@ const micro = defineCollection({ z.object({ url: z.string(), type: z.string(), + alt: z.string().optional(), }), ) .optional(), diff --git a/src/loaders/pleroma.ts b/src/loaders/pleroma.ts index be61329..0dbb26b 100644 --- a/src/loaders/pleroma.ts +++ b/src/loaders/pleroma.ts @@ -557,6 +557,7 @@ export function pleromaLoader(config: PleromaFeedConfig): Loader { .map((attachment) => ({ url: attachment.url, type: `image/${attachment.url.split(".").pop() || "jpeg"}`, + alt: attachment.description || undefined, })); } diff --git a/src/pages/micro/rss.xml.ts b/src/pages/micro/rss.xml.ts index 1fd6f53..5b388b6 100644 --- a/src/pages/micro/rss.xml.ts +++ b/src/pages/micro/rss.xml.ts @@ -21,8 +21,8 @@ export const GET = async (context: APIContext) => { if (post.data.attachments && post.data.attachments.length > 0) { const imagesHtml = post.data.attachments .map( - (att: { url: string; type: string }) => - `<p><img src="${att.url}" alt="Attachment" style="max-width: 100%; height: auto;" /></p>`, + (att) => + `<p><img src="${att.url}" alt="${att.alt || "Image"}" style="max-width: 100%; height: auto;" /></p>`, ) .join(""); fullContent += imagesHtml; |
