diff --git a/pages.go b/pages.go index 237fb2d..b1c234b 100644 --- a/pages.go +++ b/pages.go @@ -21,6 +21,29 @@ const ( Other ) +var ( + //go:embed templates/opengraph.html + tmplOpenGraph string + OpenGraphTemplate = tmpl.MustCompile(&OpenGraphPartial{}) +) + +//tmpl:bind head_common.html +type OpenGraphPartial struct { + IsTwitter bool + TitleizedContent string + Title string + TwitterTitle string + Proxy string + AuthorLong string + TextImageURL string + Video string + VideoType string + Image string + Description string +} + +func (*OpenGraphPartial) TemplateText() string { return tmplOpenGraph } + var ( //go:embed templates/head_common.html tmplHeadCommon string @@ -33,6 +56,7 @@ type HeadCommonPartial struct { TailwindDebugStuff template.HTML NaddrNaked string NeventNaked string + Oembed string } func (*HeadCommonPartial) TemplateText() string { return tmplHeadCommon } @@ -185,32 +209,22 @@ var ( ) type NotePage struct { + OpenGraphPartial `tmpl:"opengraph"` HeadCommonPartial `tmpl:"head_common"` TopPartial `tmpl:"top"` DetailsPartial `tmpl:"details"` ClientsPartial `tmpl:"clients"` FooterPartial `tmpl:"footer"` - AuthorLong string Content template.HTML CreatedAt string - Description string - Image string Metadata nostr.ProfileMetadata Npub string NpubShort string - Oembed string ParentLink template.HTML - Proxy string SeenOn []string - IsTwitter bool Subject string - TextImageURL string - Title string TitleizedContent string - TwitterTitle string - Video string - VideoType string } func (*NotePage) TemplateText() string { return tmplNote } @@ -253,31 +267,23 @@ var ( ) type FileMetadataPage struct { + OpenGraphPartial `tmpl:"opengraph"` HeadCommonPartial `tmpl:"head_common"` TopPartial `tmpl:"top"` DetailsPartial `tmpl:"details"` ClientsPartial `tmpl:"clients"` FooterPartial `tmpl:"footer"` - AuthorLong string Content template.HTML CreatedAt string - Description string Metadata nostr.ProfileMetadata Npub string NpubShort string - Oembed string ParentLink template.HTML - Proxy string SeenOn []string Style Style Subject string - TextImageURL string - Title string TitleizedContent string - TwitterTitle string - Video string - VideoType string // Specific Metadata Url string diff --git a/render_event.go b/render_event.go index 3ed7f49..631f36a 100644 --- a/render_event.go +++ b/render_event.go @@ -253,8 +253,22 @@ func renderEvent(w http.ResponseWriter, r *http.Request) { }) case Note: err = NoteTemplate.Render(w, &NotePage{ + OpenGraphPartial: OpenGraphPartial{ + IsTwitter: style == StyleTwitter, + Proxy: "https://" + host + "/njump/proxy?src=", + Title: title, + TwitterTitle: twitterTitle, + TitleizedContent: titleizedContent, + TextImageURL: textImageURL, + Image: data.image, + Video: data.video, + VideoType: data.videoType, + Description: description, + AuthorLong: data.authorLong, + }, HeadCommonPartial: HeadCommonPartial{ IsProfile: false, + Oembed: oembed, TailwindDebugStuff: tailwindDebugStuff, NaddrNaked: data.naddrNaked, NeventNaked: data.neventNaked, @@ -264,25 +278,14 @@ func renderEvent(w http.ResponseWriter, r *http.Request) { Clients: generateClientList(style, code, data.event), }, - AuthorLong: data.authorLong, Content: template.HTML(data.content), CreatedAt: data.createdAt, - Description: description, - Image: data.image, Metadata: data.metadata, Npub: data.npub, NpubShort: data.npubShort, - Oembed: oembed, ParentLink: data.parentLink, - Proxy: "https://" + host + "/njump/proxy?src=", - IsTwitter: style == StyleTwitter, Subject: subject, - TextImageURL: textImageURL, - Title: title, TitleizedContent: titleizedContent, - TwitterTitle: twitterTitle, - Video: data.video, - VideoType: data.videoType, }) case FileMetadata: thisImage := data.kind1063Metadata.image @@ -290,6 +293,19 @@ func renderEvent(w http.ResponseWriter, r *http.Request) { thisImage = data.image } err = FileMetadataTemplate.Render(w, &FileMetadataPage{ + OpenGraphPartial: OpenGraphPartial{ + IsTwitter: style == StyleTwitter, + Proxy: "https://" + host + "/njump/proxy?src=", + TitleizedContent: titleizedContent, + TwitterTitle: twitterTitle, + Title: title, + TextImageURL: textImageURL, + Video: data.video, + VideoType: data.videoType, + Image: thisImage, + Description: description, + AuthorLong: data.authorLong, + }, HeadCommonPartial: HeadCommonPartial{ IsProfile: false, TailwindDebugStuff: tailwindDebugStuff, @@ -301,20 +317,13 @@ func renderEvent(w http.ResponseWriter, r *http.Request) { Clients: generateClientList(style, code, data.event), }, - AuthorLong: data.authorLong, CreatedAt: data.createdAt, Metadata: data.metadata, - Description: description, Npub: data.npub, NpubShort: data.npubShort, Style: style, Subject: subject, - TextImageURL: textImageURL, - Title: title, TitleizedContent: titleizedContent, - TwitterTitle: twitterTitle, - Video: data.video, - VideoType: data.videoType, Url: data.kind1063Metadata.url, M: data.kind1063Metadata.m, Aes256Gcm: data.kind1063Metadata.aes256gcm, diff --git a/templates/file_metadata.html b/templates/file_metadata.html index 51945c0..e594d66 100644 --- a/templates/file_metadata.html +++ b/templates/file_metadata.html @@ -2,50 +2,7 @@
-