From 76b9797c41efaf724c71827d8a6a7b0f0fcc5574 Mon Sep 17 00:00:00 2001 From: Gigi Date: Fri, 7 Nov 2025 19:39:02 +0100 Subject: [PATCH] feat: add article tags and image alt text to OG metadata - Add tags field to ArticleMetadata type (extracted from 't' tags) - Add imageAlt field to ArticleMetadata type (uses title as fallback) - Extract 't' tags from article events in fetchArticleMetadataViaRelays - Generate multiple article:tag meta tags in HTML output - Add og:image:alt meta tag for better accessibility This improves SEO and social media previews by including article categorization tags and image descriptions. --- api/services/articleMeta.ts | 13 ++++++++++++- api/services/ogHtml.ts | 10 +++++++++- api/services/ogStore.ts | 2 ++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/api/services/articleMeta.ts b/api/services/articleMeta.ts index a54c9a3e..71ad29bf 100644 --- a/api/services/articleMeta.ts +++ b/api/services/articleMeta.ts @@ -70,6 +70,15 @@ export async function fetchArticleMetadataViaRelays(naddr: string): Promise tag[0] === 't' && tag[1]) + .map((tag) => tag[1]) + .filter((tag) => tag.length > 0) || [] + + // Generate image alt text (use title as fallback) + const imageAlt = title || 'Article cover image' + let authorName = pointer.pubkey.slice(0, 8) + '...' if (profileEvents.length > 0) { const displayName = extractProfileDisplayName(profileEvents[0]) @@ -85,7 +94,9 @@ export async function fetchArticleMetadataViaRelays(naddr: string): Promise 0 ? tags : undefined, + imageAlt } } catch (err) { console.error('Failed to fetch article metadata via relays:', err) diff --git a/api/services/ogHtml.ts b/api/services/ogHtml.ts index 53d46a06..f2713b84 100644 --- a/api/services/ogHtml.ts +++ b/api/services/ogHtml.ts @@ -17,6 +17,12 @@ export function generateHtml(naddr: string, meta: ArticleMetadata | null): strin const description = meta?.summary || 'Your reading list for the Nostr world. A minimal nostr client for bookmark management with highlights.' const image = meta?.image?.startsWith('http') ? meta.image : `${baseUrl}${meta?.image || '/boris-social-1200.png'}` const author = meta?.author || 'Boris' + const imageAlt = meta?.imageAlt || title + + // Generate article:tag meta tags + const articleTags = meta?.tags && meta.tags.length > 0 + ? meta.tags.map((tag) => ` `).join('\n') + : '' return ` @@ -39,9 +45,11 @@ export function generateHtml(naddr: string, meta: ArticleMetadata | null): strin + - ${meta?.published ? `` : ''} + ${meta?.published ? ` ` : ''} +${articleTags} diff --git a/api/services/ogStore.ts b/api/services/ogStore.ts index 42a9a601..812429a3 100644 --- a/api/services/ogStore.ts +++ b/api/services/ogStore.ts @@ -25,6 +25,8 @@ export type ArticleMetadata = { image: string author: string published?: number + tags?: string[] + imageAlt?: string } export async function getArticleMeta(naddr: string): Promise {