Skip to content

Commit

Permalink
fix youtube autoexpand
Browse files Browse the repository at this point in the history
  • Loading branch information
rystaf committed Apr 20, 2024
1 parent 1347a2e commit 5ab5047
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ var funcMap = template.FuncMap{
}
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 {
if p.ThumbnailURL.IsValid() {
return p.ThumbnailURL.String() + "?format=jpg&thumbnail=96"
Expand Down
2 changes: 1 addition & 1 deletion templates/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
</a>
({{ domain . }})
</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">
submitted
<span title="{{.Post.Published.Time}}">{{ humanize .Post.Published.Time -}}</span>
Expand Down

0 comments on commit 5ab5047

Please sign in to comment.