diff --git a/public/link.png b/public/link.png index cd1ddb3..0daeb9c 100644 Binary files a/public/link.png and b/public/link.png differ diff --git a/public/photo.png b/public/photo.png new file mode 100644 index 0000000..96eec15 Binary files /dev/null and b/public/photo.png differ diff --git a/public/style.css b/public/style.css index 0be05bb..25c7730 100644 --- a/public/style.css +++ b/public/style.css @@ -38,7 +38,7 @@ summary { height: 52px; width: 70px; background-repeat: no-repeat; - background-size: cover; + background-size: contain; background-position: center; } .rank { @@ -809,10 +809,14 @@ nav .host { font-size: 12px; } -nav .spacer { +nav div.spacer { height: 32px; position: relative; } +nav span.spacer { + height: 20px; + display: inline-block; +} nav .space a { z-index: 100; } diff --git a/public/text.png b/public/text.png index 564a031..4dc1246 100644 Binary files a/public/text.png and b/public/text.png differ diff --git a/routes.go b/routes.go index b7fa609..1dfaca9 100644 --- a/routes.go +++ b/routes.go @@ -25,6 +25,21 @@ import ( "golang.org/x/text/message" ) +var pictrs = regexp.MustCompile(`\/pictrs\/image\/([a-z0-9\-]+)\.([a-z]+)$`) +var imgur = regexp.MustCompile(`^https:\/\/(i\.)?imgur.com\/([a-zA-Z0-9]{5,})(\.[a-zA-Z0-9]+)?`) + +var isImage = func(u string) bool { + p, err := url.Parse(u) + if err != nil || p.Path == "" { + return false + } + ext := filepath.Ext(p.Path) + if ext == ".jpeg" || ext == ".jpg" || ext == ".png" || ext == ".webp" || ext == ".gif" { + return true + } + return false +} + var funcMap = template.FuncMap{ "host": func(host string) string { if l := os.Getenv("LEMMY_DOMAIN"); l != "" { @@ -112,38 +127,61 @@ var funcMap = template.FuncMap{ } return "" }, - "isImage": func(u string) bool { - p, err := url.Parse(u) - if err != nil || p.Path == "" { - return false - } - ext := filepath.Ext(p.Path) - if ext == ".jpeg" || ext == ".jpg" || ext == ".png" || ext == ".webp" || ext == ".gif" { - return true - } - return false - }, + "isImage": isImage, "isYoutube": func(u string) bool { re := regexp.MustCompile(`^((?:https?:)?\/\/)?((?:www|m)\.)?((?:youtube(-nocookie)?\.com|youtu.be))(\/(?:[\w\-]+\?v=|embed\/|live\/|v\/)?)([\w\-]+)(\S+)?$`) return re.MatchString(u) }, "thumbnail": func(p lemmy.Post) string { + if pictrs.MatchString(p.ThumbnailURL.String()) { + return p.ThumbnailURL.String() + "?format=jpg&thumbnail=64" + } else if pictrs.MatchString(p.URL.String()) { + return p.URL.String() + "?format=jpg&thumbnail=64" + } + if imgur.MatchString(p.URL.String()) { + return imgur.ReplaceAllString(p.URL.String(), "https://i.imgur.com/${2}s.jpg") + } if p.ThumbnailURL.IsValid() { - return p.ThumbnailURL.String() + "?format=jpg&thumbnail=96" + return p.ThumbnailURL.String() } - re := regexp.MustCompile(`\/pictrs\/image\/([a-z0-9\-]+)\.([a-z]+)$`) - if re.MatchString(p.URL.String()) { - return p.URL.String() + "?format=jpg&thumbnail=96" - } - re = regexp.MustCompile(`^https:\/\/(i\.)?imgur.com\/([a-zA-Z0-9]{5,})(\.[a-zA-Z0-9]+)?`) - if re.MatchString(p.URL.String()) { - return re.ReplaceAllString(p.URL.String(), "https://i.imgur.com/${2}s.jpg") + if isImage(p.URL.String()) { + return "/_/static/photo.png" } if p.URL.IsValid() { return "/_/static/link.png" } return "/_/static/text.png" }, + "banner": func(site lemmy.Site) string { + bannerURL := "" + if site.Banner.IsValid() { + bannerURL = site.Banner.String() + } else if site.Icon.IsValid() { + bannerURL = site.Icon.String() + } + if pictrs.MatchString(bannerURL) { + return bannerURL + "?format=jpg&thumbnail=300" + } + return bannerURL + }, + "cbanner": func(c lemmy.Community) string { + bannerURL := "" + if c.Banner.IsValid() { + bannerURL = c.Banner.String() + } else if c.Icon.IsValid() { + bannerURL = c.Icon.String() + } + if pictrs.MatchString(bannerURL) { + return bannerURL + "?format=jpg&thumbnail=300" + } + return bannerURL + }, + "shrink": func(u string) string { + if pictrs.MatchString(u) { + return u + "?format=png&thumbnail=60" + } + return u + }, "humanize": humanize.Time, "markdown": func(host string, body string) template.HTML { var buf bytes.Buffer @@ -452,7 +490,11 @@ func GetIcon(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { w.Write([]byte("404 - Not Found")) return } - iresp, err := state.HTTPClient.Get(resp.SiteView.Site.Icon.String()) + u := resp.SiteView.Site.Icon.String() + if pictrs.MatchString(u) { + u += "?format=jpg&thumbnail=60" + } + iresp, err := state.HTTPClient.Get(u) if err != nil { fmt.Println(err) w.WriteHeader(http.StatusInternalServerError) diff --git a/templates/login.html b/templates/login.html index c2437a0..7ce4439 100644 --- a/templates/login.html +++ b/templates/login.html @@ -24,10 +24,11 @@
- +
- {{ host .Host}} - sign up or login + {{ host .Host}} - sign up or login + {{ if .Alert }}
diff --git a/templates/nav.html b/templates/nav.html index f69c630..41177e7 100644 --- a/templates/nav.html +++ b/templates/nav.html @@ -33,14 +33,15 @@ |
{{- else}} - log in or sign up| + log in or sign up + | settings {{- end}}
- +
{{- if .Community }} diff --git a/templates/settings.html b/templates/settings.html index 9d807df..3f10064 100644 --- a/templates/settings.html +++ b/templates/settings.html @@ -43,7 +43,7 @@
- +
{{host .Host}} - settings diff --git a/templates/sidebar.html b/templates/sidebar.html index 3069e01..b9603ac 100644 --- a/templates/sidebar.html +++ b/templates/sidebar.html @@ -62,10 +62,8 @@ {{- end -}} {{- if and .Site (not .Community) (not .User) }} - {{- if .Site.SiteView.Site.Banner.IsValid }} - - {{- else if .Site.SiteView.Site.Icon.IsValid }} - + {{- if or .Site.SiteView.Site.Banner.IsValid .Site.SiteView.Site.Icon.IsValid }} + {{- end }}

{{ .Site.SiteView.Site.Name }}

{{ printer .Site.SiteView.Counts.Users }} readers
@@ -84,10 +82,8 @@ {{- end -}} {{- if .Community }} - {{- if .Community.CommunityView.Community.Banner.IsValid }} - - {{- else if .Community.CommunityView.Community.Icon.IsValid }} - + {{- if or .Community.CommunityView.Community.Banner.IsValid .Community.CommunityView.Community.Icon.IsValid }} + {{- end }}

{{ if ne .Community.CommunityView.Community.Title ""}}{{ .Community.CommunityView.Community.Title }}{{ else }}{{ .Community.CommunityView.Community.Name }}{{end}}

{{- if .Session }}