mirror of
https://github.com/rystaf/mlmym.git
synced 2024-11-05 06:43:21 +00:00
display imgur thumbnails. fixes #17
This commit is contained in:
parent
48d12530fe
commit
e46820ed3f
12
routes.go
12
routes.go
|
@ -111,6 +111,18 @@ var funcMap = template.FuncMap{
|
|||
}
|
||||
return false
|
||||
},
|
||||
"thumbnail": func(p types.Post) string {
|
||||
if p.ThumbnailURL.IsValid() {
|
||||
return p.ThumbnailURL.String() + "?format=jpg&thumbnail=96"
|
||||
}
|
||||
re := regexp.MustCompile(`^https:\/\/i.imgur.com\/([a-zA-Z0-9]+)\.([a-z]+)$`)
|
||||
if re.MatchString(p.URL.String()) {
|
||||
return re.ReplaceAllString(p.URL.String(), "https://i.imgur.com/${1}s.$2")
|
||||
} else if p.URL.IsValid() {
|
||||
return "/_/static/link.png"
|
||||
}
|
||||
return "/_/static/text.png"
|
||||
},
|
||||
"humanize": humanize.Time,
|
||||
"markdown": func(host string, body string) template.HTML {
|
||||
var buf bytes.Buffer
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
{{ end }}
|
||||
{{ if ne .State.Op "vote_post" }}
|
||||
</div>
|
||||
<div class="thumb"><div {{ if and .Post.NSFW (not (and .State.Community .State.Community.CommunityView.Community.NSFW))}}class="img-blur"{{end}} style="background-image: url({{if .Post.ThumbnailURL.IsValid}}{{.Post.ThumbnailURL.String}}?format=jpg&thumbnail=96{{else if .Post.URL.IsValid}}/_/static/link.png{{else}}/_/static/text.png{{end}})"></div></div>
|
||||
<div class="thumb"><div {{ if and .Post.NSFW (not (and .State.Community .State.Community.CommunityView.Community.NSFW))}}class="img-blur"{{end}} style="background-image: url({{thumbnail .Post}})"></div></div>
|
||||
<div class="entry">
|
||||
<div class="title">
|
||||
<a class="url" href="{{ if .Post.URL.IsValid }}{{ .Post.URL }}{{ else }}/{{ .State.Host }}/post/{{ .Post.ID }}{{ end }}">{{ rmmarkdown .Post.Name }}</a>
|
||||
|
|
Loading…
Reference in a new issue