support multiple og:image tags (#2305)

zio/stable
snek 2023-12-27 09:13:53 -08:00 committed by GitHub
parent b5d53ef0b9
commit 929987f806
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -336,7 +336,11 @@ func (srv *Server) WebPost(c echo.Context) error {
data["postView"] = postView data["postView"] = postView
data["requestURI"] = fmt.Sprintf("https://%s%s", req.Host, req.URL.Path) data["requestURI"] = fmt.Sprintf("https://%s%s", req.Host, req.URL.Path)
if postView.Embed != nil && postView.Embed.EmbedImages_View != nil { if postView.Embed != nil && postView.Embed.EmbedImages_View != nil {
data["imgThumbUrl"] = postView.Embed.EmbedImages_View.Images[0].Thumb var thumbUrls []string
for i := range postView.Embed.EmbedImages_View.Images {
thumbUrls = append(thumbUrls, postView.Embed.EmbedImages_View.Images[i].Thumb)
}
data["imgThumbUrls"] = thumbUrls
} }
return c.Render(http.StatusOK, "post.html", data) return c.Render(http.StatusOK, "post.html", data)
} }

View File

@ -25,8 +25,10 @@
<meta name="description" content="{{ postView.Record.Val.Text }}"> <meta name="description" content="{{ postView.Record.Val.Text }}">
<meta property="og:description" content="{{ postView.Record.Val.Text }}"> <meta property="og:description" content="{{ postView.Record.Val.Text }}">
{% endif -%} {% endif -%}
{%- if imgThumbUrl %} {%- if imgThumbUrls %}
{% for imgThumbUrl in imgThumbUrls %}
<meta property="og:image" content="{{ imgThumbUrl }}"> <meta property="og:image" content="{{ imgThumbUrl }}">
{% endfor %}
<meta name="twitter:card" content="summary_large_image"> <meta name="twitter:card" content="summary_large_image">
{%- elif postView.Author.Avatar %} {%- elif postView.Author.Avatar %}
{# Don't use avatar image in cards; usually looks bad #} {# Don't use avatar image in cards; usually looks bad #}