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 @@ - {{.TitleizedContent}} - - - {{ if eq .Style "twitter" }} - - {{ end }} - - - {{ if not (eq "" .TextImageURL) }} - - - - - {{ else }} - - - {{ if not (eq "" .Image) }} - - - {{ end }} {{ if not (eq "" .Video) }} - - - - {{ end }} {{ end }} - - {{ if not (eq "" .Description) }} - - - {{ end }} - - - {{ if not (eq "" .Oembed) }} - - - {{ end }} - + {{template "opengraph" .OpenGraphPartial}} {{template "head_common" .HeadCommonPartial}} @@ -97,7 +54,7 @@ >
{{ if (not (eq "" .Subject))}}

{{.Subject}}

@@ -109,16 +66,25 @@ {{ if (not (eq "" .Image))}} - {{ .Alt }} - {{ else if (eq "image" .MType)}} - {{ .Alt }} - {{ else if (eq "video" .MType)}} - + {{ .Alt }} + {{ else if (eq "image" .MType)}} + {{ .Alt }} + {{ else if (eq "video" .MType)}} + {{ end }} - Download file - + Download file
{{template "details" .DetailsPartial}} diff --git a/templates/head_common.html b/templates/head_common.html index 0b9a4d2..e4ca8ea 100644 --- a/templates/head_common.html +++ b/templates/head_common.html @@ -1,5 +1,16 @@ +{{ if not (eq "" .Oembed) }} + + +{{ end }} + + + {{if .IsProfile}} - {{.TitleizedContent}} - - - {{ if .IsTwitter }} - - {{ end }} - - - {{ if not (eq "" .TextImageURL) }} - - - - - {{ else }} - - - {{ if not (eq "" .Image) }} - - - {{ end }} {{ if not (eq "" .Video) }} - - - - {{ end }} {{ end }} - - {{ if not (eq "" .Description) }} - - - {{ end }} - - - {{ if not (eq "" .Oembed) }} - - - {{ end }} - + {{template "opengraph" .OpenGraphPartial}} {{template "head_common" .HeadCommonPartial}} diff --git a/templates/opengraph.html b/templates/opengraph.html new file mode 100644 index 0000000..5e63cf7 --- /dev/null +++ b/templates/opengraph.html @@ -0,0 +1,29 @@ +{{.TitleizedContent}} + + +{{ if .IsTwitter }} + +{{ end }} + + +{{ if not (eq "" .TextImageURL) }} + + + + +{{ else }} + + +{{ if not (eq "" .Image) }} + + +{{ end }} {{ if not (eq "" .Video) }} + + + +{{ end }} {{ end }} + +{{ if not (eq "" .Description) }} + + +{{ end }}