diff --git a/models/avatar.go b/models/avatar.go index ac260fbd93..166ca337ca 100644 --- a/models/avatar.go +++ b/models/avatar.go @@ -40,6 +40,12 @@ func DefaultAvatarLink() string { // determined by the avatar-hosting service. const DefaultAvatarSize = -1 +// DefaultAvatarPixelSize is the default size in pixels of a rendered avatar +const DefaultAvatarPixelSize = 28 + +// AvatarRenderedSizeFactor is the factor by which the default size is increased for finer rendering +const AvatarRenderedSizeFactor = 2 + // HashEmail hashes email address to MD5 string. // https://en.gravatar.com/site/implement/hash/ func HashEmail(email string) string { diff --git a/modules/repository/commits.go b/modules/repository/commits.go index fd8b8d927a..6b67c2c262 100644 --- a/modules/repository/commits.go +++ b/modules/repository/commits.go @@ -118,12 +118,14 @@ func (pc *PushCommits) AvatarLink(email string) string { return avatar } + size := models.DefaultAvatarPixelSize * models.AvatarRenderedSizeFactor + u, ok := pc.emailUsers[email] if !ok { var err error u, err = models.GetUserByEmail(email) if err != nil { - pc.avatars[email] = models.HashedAvatarLink(email) + pc.avatars[email] = models.SizedAvatarLink(email, size) if !models.IsErrUserNotExist(err) { log.Error("GetUserByEmail: %v", err) return "" @@ -133,7 +135,7 @@ func (pc *PushCommits) AvatarLink(email string) string { } } if u != nil { - pc.avatars[email] = u.RelAvatarLink() + pc.avatars[email] = u.RealSizedAvatarLink(size) } return pc.avatars[email] diff --git a/modules/repository/commits_test.go b/modules/repository/commits_test.go index cb00e19c2e..16677fe8a6 100644 --- a/modules/repository/commits_test.go +++ b/modules/repository/commits_test.go @@ -112,11 +112,13 @@ func TestPushCommits_AvatarLink(t *testing.T) { pushCommits.Len = len(pushCommits.Commits) assert.Equal(t, - "/user/avatar/user2/-1", + "https://secure.gravatar.com/avatar/ab53a2911ddf9b4817ac01ddcd3d975f?d=identicon&s=56", pushCommits.AvatarLink("user2@example.com")) assert.Equal(t, - "/avatar/"+fmt.Sprintf("%x", md5.Sum([]byte("nonexistent@example.com"))), + "https://secure.gravatar.com/avatar/"+ + fmt.Sprintf("%x", md5.Sum([]byte("nonexistent@example.com")))+ + "?d=identicon&s=56", pushCommits.AvatarLink("nonexistent@example.com")) } diff --git a/modules/templates/helper.go b/modules/templates/helper.go index 0b5ae0f013..f7c10c3698 100644 --- a/modules/templates/helper.go +++ b/modules/templates/helper.go @@ -340,6 +340,7 @@ func NewFuncMap() []template.FuncMap { }, "svg": SVG, "avatar": Avatar, + "avatarHTML": AvatarHTML, "avatarByEmail": AvatarByEmail, "repoAvatar": RepoAvatar, "SortArrow": func(normSort, revSort, urlSort string, isDefault bool) template.HTML { @@ -519,7 +520,8 @@ func parseOthers(defaultSize int, defaultClass string, others ...interface{}) (i return size, class } -func avatarHTML(src string, size int, class string, name string) template.HTML { +// AvatarHTML creates the HTML for an avatar +func AvatarHTML(src string, size int, class string, name string) template.HTML { sizeStr := fmt.Sprintf(`%d`, size) if name == "" { @@ -548,33 +550,33 @@ func SVG(icon string, others ...interface{}) template.HTML { // Avatar renders user avatars. args: user, size (int), class (string) func Avatar(user *models.User, others ...interface{}) template.HTML { - size, class := parseOthers(28, "ui avatar image", others...) + size, class := parseOthers(models.DefaultAvatarPixelSize, "ui avatar image", others...) - src := user.RealSizedAvatarLink(size * 2) // request double size for finer rendering + src := user.RealSizedAvatarLink(size * models.AvatarRenderedSizeFactor) if src != "" { - return avatarHTML(src, size, class, user.DisplayName()) + return AvatarHTML(src, size, class, user.DisplayName()) } return template.HTML("") } // RepoAvatar renders repo avatars. args: repo, size(int), class (string) func RepoAvatar(repo *models.Repository, others ...interface{}) template.HTML { - size, class := parseOthers(28, "ui avatar image", others...) + size, class := parseOthers(models.DefaultAvatarPixelSize, "ui avatar image", others...) src := repo.RelAvatarLink() if src != "" { - return avatarHTML(src, size, class, repo.FullName()) + return AvatarHTML(src, size, class, repo.FullName()) } return template.HTML("") } // AvatarByEmail renders avatars by email address. args: email, name, size (int), class (string) func AvatarByEmail(email string, name string, others ...interface{}) template.HTML { - size, class := parseOthers(28, "ui avatar image", others...) - src := models.SizedAvatarLink(email, size*2) // request double size for finer rendering + size, class := parseOthers(models.DefaultAvatarPixelSize, "ui avatar image", others...) + src := models.SizedAvatarLink(email, size*models.AvatarRenderedSizeFactor) if src != "" { - return avatarHTML(src, size, class, name) + return AvatarHTML(src, size, class, name) } return template.HTML("") diff --git a/templates/admin/hook_new.tmpl b/templates/admin/hook_new.tmpl index 8eeb0e5264..dabd568f93 100644 --- a/templates/admin/hook_new.tmpl +++ b/templates/admin/hook_new.tmpl @@ -11,23 +11,23 @@ {{end}}
{{ if gt .Publisher.ID 0 }} {{.Publisher.GetDisplayName}} {{else}} Ghost diff --git a/templates/repo/settings/webhook/list.tmpl b/templates/repo/settings/webhook/list.tmpl index 29994d8197..47ed37cc33 100644 --- a/templates/repo/settings/webhook/list.tmpl +++ b/templates/repo/settings/webhook/list.tmpl @@ -6,31 +6,31 @@
{{ end }} @@ -117,7 +117,7 @@ {{if .OriginalAuthor}} {{svg "octicon-mark-github" 16 "mr-2"}}{{.OriginalAuthor}} {{else if .Publisher}} - {{avatar .Publisher 28 "img-10"}} + {{avatar .Publisher 20}} diff --git a/templates/repo/settings/webhook/new.tmpl b/templates/repo/settings/webhook/new.tmpl index fc78db8648..ac5d1886b2 100644 --- a/templates/repo/settings/webhook/new.tmpl +++ b/templates/repo/settings/webhook/new.tmpl @@ -8,23 +8,23 @@ {{if .PageIsSettingsHooksNew}}{{.i18n.Tr "repo.settings.add_webhook"}}{{else}}{{.i18n.Tr "repo.settings.update_webhook"}}{{end}}