fix youtube autoexpand

This commit is contained in:
Ryan Stafford 2024-04-19 22:49:22 -04:00
parent 1347a2e949
commit 5ab5047ba7
2 changed files with 8 additions and 1 deletions

View file

@ -123,6 +123,13 @@ var funcMap = template.FuncMap{
} }
return false return false
}, },
"isYoutube": func(u string) bool {
re := regexp.MustCompile(`^((?:https?:)?\/\/)?((?:www|m)\.)?((?:youtube(-nocookie)?\.com|youtu.be))(\/(?:[\w\-]+\?v=|embed\/|live\/|v\/)?)([\w\-]+)(\S+)?$`)
if re.MatchString(u) {
return true
}
return false
},
"thumbnail": func(p lemmy.Post) string { "thumbnail": func(p lemmy.Post) string {
if p.ThumbnailURL.IsValid() { if p.ThumbnailURL.IsValid() {
return p.ThumbnailURL.String() + "?format=jpg&thumbnail=96" return p.ThumbnailURL.String() + "?format=jpg&thumbnail=96"

View file

@ -41,7 +41,7 @@
</a> </a>
({{ domain . }}) ({{ domain . }})
</div> </div>
<div class="expando-button{{ if and (not (and .Post.Body.IsValid .Post.Body.String )) (not (isImage .Post.URL.String)) }} hidden{{else if eq .Rank 0}} open{{ end }}"></div> <div class="expando-button{{ if and (not (and .Post.Body.IsValid .Post.Body.String )) (not (isImage .Post.URL.String)) (not (isYoutube .Post.URL.String)) }} hidden{{else if eq .Rank 0}} open{{ end }}"></div>
<div class="meta"> <div class="meta">
submitted submitted
<span title="{{.Post.Published.Time}}">{{ humanize .Post.Published.Time -}}</span> <span title="{{.Post.Published.Time}}">{{ humanize .Post.Published.Time -}}</span>