diff --git a/routes.go b/routes.go index fc5c609..c8c6ce8 100644 --- a/routes.go +++ b/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 diff --git a/templates/post.html b/templates/post.html index ec3de02..03663b7 100644 --- a/templates/post.html +++ b/templates/post.html @@ -21,7 +21,7 @@ {{ end }} {{ if ne .State.Op "vote_post" }} -
+
{{ rmmarkdown .Post.Name }}