aboutsummaryrefslogtreecommitdiffstats
path: root/modules/templates
diff options
context:
space:
mode:
authorsilverwind <me@silverwind.io>2020-12-09 01:12:15 +0100
committerGitHub <noreply@github.com>2020-12-09 01:12:15 +0100
commitc05701dd7d72aea75c67fbb07df928c192474686 (patch)
tree807d295c28ad57950120e0b14596168902efde0d /modules/templates
parent658e90a1141a03e5249770a6a670b818fe307e1d (diff)
downloadgitea-c05701dd7d72aea75c67fbb07df928c192474686.tar.gz
gitea-c05701dd7d72aea75c67fbb07df928c192474686.zip
Fix frontpage avatars (#13853)
The frontpage uses a rather strange method to obtain the commit's avatar which I've overlooked earlier. I don't exactly understand how it works but this change fixes the wrong default avatars by using the function that was in previous use. Also introduced a few constants for size an size increase factor. Fixes: https://github.com/go-gitea/gitea/issues/13844
Diffstat (limited to 'modules/templates')
-rw-r--r--modules/templates/helper.go20
1 files changed, 11 insertions, 9 deletions
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("")