From 261e1b8b38dd6eb5029f437fcd950686daa22911 Mon Sep 17 00:00:00 2001 From: dtonon Date: Thu, 30 May 2024 22:31:00 +0200 Subject: [PATCH] Add cover image to long format notes --- data.go | 6 ++++++ note.templ | 3 +++ pages.go | 1 + render_event.go | 1 + 4 files changed, 11 insertions(+) diff --git a/data.go b/data.go index 6e32421..f9f87f8 100644 --- a/data.go +++ b/data.go @@ -35,6 +35,7 @@ type Data struct { video string videoType string image string + cover string content string alt string kind1063Metadata *Kind1063Metadata @@ -171,6 +172,11 @@ func grabData(ctx context.Context, code string, isProfileSitemap bool) (*Data, e } data.kindNIP = kindNIPs[event.Kind] + image := event.Tags.GetFirst([]string{"image", ""}) + if event.Kind == 30023 && image != nil { + data.cover = (*image)[1] + } + if event.Kind == 1063 { if data.kind1063Metadata.IsImage() { data.image = data.kind1063Metadata.URL diff --git a/note.templ b/note.templ index 7d91499..8c018cb 100644 --- a/note.templ +++ b/note.templ @@ -18,6 +18,9 @@ templ noteTemplate(params NotePageParams) { { params.Metadata.ShortName() } on Nostr: { params.TitleizedContent } } + if params.Cover != "" { + { + }
@templ.Raw(params.Content) diff --git a/pages.go b/pages.go index d5770c6..e113ae7 100644 --- a/pages.go +++ b/pages.go @@ -196,6 +196,7 @@ type NotePageParams struct { Details DetailsParams Content template.HTML + Cover string Subject string TitleizedContent string Clients []ClientReference diff --git a/render_event.go b/render_event.go index 3cc32fb..e8c3baa 100644 --- a/render_event.go +++ b/render_event.go @@ -386,6 +386,7 @@ func renderEvent(w http.ResponseWriter, r *http.Request) { Clients: generateClientList(data.event.Kind, enhancedCode), Details: detailsData, Content: template.HTML(content), + Cover: data.cover, Subject: subject, TitleizedContent: titleizedContent, })