From 5c2de3a9ea783d940794bf5f707b000a21def85b Mon Sep 17 00:00:00 2001 From: Unknwon Date: Wed, 18 Apr 2018 19:40:35 -0400 Subject: pkg/template: fix Gravatar URLs are badly generated (#5157) --- gogs.go | 2 +- pkg/template/template.go | 17 +++++++++-------- pkg/tool/tool.go | 8 ++++++++ templates/.VERSION | 2 +- templates/user/profile.tmpl | 4 ++-- 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/gogs.go b/gogs.go index 70f19b50..10fe8bc5 100644 --- a/gogs.go +++ b/gogs.go @@ -16,7 +16,7 @@ import ( "github.com/gogits/gogs/pkg/setting" ) -const APP_VER = "0.11.45.0416" +const APP_VER = "0.11.46.0418" func init() { setting.AppVer = APP_VER diff --git a/pkg/template/template.go b/pkg/template/template.go index f93aca74..dc633885 100644 --- a/pkg/template/template.go +++ b/pkg/template/template.go @@ -60,14 +60,15 @@ func NewFuncMap() []template.FuncMap { "LoadTimes": func(startTime time.Time) string { return fmt.Sprint(time.Since(startTime).Nanoseconds()/1e6) + "ms" }, - "AvatarLink": tool.AvatarLink, - "Safe": Safe, - "Sanitize": bluemonday.UGCPolicy().Sanitize, - "Str2html": Str2html, - "TimeSince": tool.TimeSince, - "RawTimeSince": tool.RawTimeSince, - "FileSize": tool.FileSize, - "Subtract": tool.Subtract, + "AvatarLink": tool.AvatarLink, + "AppendAvatarSize": tool.AppendAvatarSize, + "Safe": Safe, + "Sanitize": bluemonday.UGCPolicy().Sanitize, + "Str2html": Str2html, + "TimeSince": tool.TimeSince, + "RawTimeSince": tool.RawTimeSince, + "FileSize": tool.FileSize, + "Subtract": tool.Subtract, "Add": func(a, b int) int { return a + b }, diff --git a/pkg/tool/tool.go b/pkg/tool/tool.go index 43b4b1d8..333790fe 100644 --- a/pkg/tool/tool.go +++ b/pkg/tool/tool.go @@ -207,6 +207,14 @@ func AvatarLink(email string) (url string) { return url } +// AppendAvatarSize appends avatar size query parameter to the URL in the correct format. +func AppendAvatarSize(url string, size int) string { + if strings.Contains(url, "?") { + return url + "&s=" + com.ToStr(size) + } + return url + "?s=" + com.ToStr(size) +} + // Seconds-based time units const ( Minute = 60 diff --git a/templates/.VERSION b/templates/.VERSION index afb39e21..e5c924f0 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.11.45.0416 \ No newline at end of file +0.11.46.0418 \ No newline at end of file diff --git a/templates/user/profile.tmpl b/templates/user/profile.tmpl index 27c30db5..2c532c60 100644 --- a/templates/user/profile.tmpl +++ b/templates/user/profile.tmpl @@ -6,11 +6,11 @@
{{if eq .LoggedUserName .Owner.Name}} - + {{else}} - + {{end}}
-- cgit v1.2.3