bskyweb: use avatar thumbnail for post og:image fallback (#9923)
This commit is contained in:
@@ -2,12 +2,14 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/flosch/pongo2/v6"
|
"github.com/flosch/pongo2/v6"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
pongo2.RegisterFilter("canonicalize_url", filterCanonicalizeURL)
|
pongo2.RegisterFilter("canonicalize_url", filterCanonicalizeURL)
|
||||||
|
pongo2.RegisterFilter("avatar_thumbnail", filterAvatarThumbnail)
|
||||||
}
|
}
|
||||||
|
|
||||||
func filterCanonicalizeURL(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) {
|
func filterCanonicalizeURL(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) {
|
||||||
@@ -26,3 +28,8 @@ func filterCanonicalizeURL(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value
|
|||||||
// Return the cleaned URL
|
// Return the cleaned URL
|
||||||
return pongo2.AsValue(parsedURL.String()), nil
|
return pongo2.AsValue(parsedURL.String()), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func filterAvatarThumbnail(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) {
|
||||||
|
urlStr := in.String()
|
||||||
|
return pongo2.AsValue(strings.Replace(urlStr, "/img/avatar/plain/", "/img/avatar_thumbnail/plain/", 1)), nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -35,8 +35,8 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
<meta name="twitter:card" content="summary_large_image">
|
<meta name="twitter:card" content="summary_large_image">
|
||||||
{% else %}
|
{% else %}
|
||||||
<meta property="og:image" content="{{ postView.Author.Avatar }}">
|
<meta property="og:image" content="{{ postView.Author.Avatar|avatar_thumbnail }}">
|
||||||
<meta property="twitter:image" content="{{ postView.Author.Avatar }}">
|
<meta property="twitter:image" content="{{ postView.Author.Avatar|avatar_thumbnail }}">
|
||||||
<meta name="twitter:card" content="summary">
|
<meta name="twitter:card" content="summary">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<meta name="twitter:label1" content="Posted At">
|
<meta name="twitter:label1" content="Posted At">
|
||||||
|
|||||||
Reference in New Issue
Block a user