7
"xelbot.com/reprogl/container"
10
type FeaturedImage struct {
11
ImagePath sql.NullString
13
PictureTag sql.NullString
19
Path string `json:"path"`
20
Width int `json:"width"`
21
Height int `json:"height"`
22
Length int `json:"length"`
25
type SrcSetItem struct {
26
Items []SrcImage `json:"items"`
27
MimeType string `json:"type"`
30
func (i *FeaturedImage) HasImage() bool {
31
return i.PictureTag.Valid || i.ImagePath.Valid
34
func (i *FeaturedImage) HasWebp() bool {
39
srcSet := i.DecodeSrcSet()
40
data, found := srcSet["webp"]
42
return found && len(data.Items) > 0
45
func (i *FeaturedImage) HasAvif() bool {
50
srcSet := i.DecodeSrcSet()
51
data, found := srcSet["avif"]
53
return found && len(data.Items) > 0
56
func (i *FeaturedImage) DecodeSrcSet() map[string]SrcSetItem {
57
data := make(map[string]SrcSetItem)
59
raw := []byte(i.SrcSet.String)
61
err := json.Unmarshal(raw, &data)
71
func (i *FeaturedImage) SrcImageForOpenGraph() *SrcImage {
72
srcSet := i.DecodeSrcSet()
73
if srcSetItem, found := srcSet["origin"]; found {
74
return &srcSetItem.Items[0]
80
func (i *FeaturedImage) GetRssEnclosure() *RssEnclosure {
81
srcSet := i.DecodeSrcSet()
82
if srcSetItem, found := srcSet["origin"]; found {
84
Url: container.GetConfig().CDNBaseURL + "/uploads/" + srcSetItem.Items[0].Path,
85
Length: srcSetItem.Items[0].Length,
86
MimeType: srcSetItem.MimeType,