diff options
author | silverwind <me@silverwind.io> | 2020-12-08 05:14:28 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-07 23:14:28 -0500 |
commit | e7938c9c44384e044afba14d5a86b1ba32520dd3 (patch) | |
tree | a813d29893239c867324d2e579022e99ad95deb2 /modules | |
parent | 9b22ada0a786494a69cf8aedb3576f9e252b2c79 (diff) | |
download | gitea-e7938c9c44384e044afba14d5a86b1ba32520dd3.tar.gz gitea-e7938c9c44384e044afba14d5a86b1ba32520dd3.zip |
Repo avatar fixes (#13891)
- Split up avatar rendering helpers for performance
- Fix showing repo SVG icon when no avatar is set
- Make repo SVG and avatar same size at 32px
- Fix fork line by adding vertical flexbox on repo title
Co-authored-by: 6543 <6543@obermui.de>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'modules')
-rw-r--r-- | modules/templates/helper.go | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/modules/templates/helper.go b/modules/templates/helper.go index 5af1addb60..0b5ae0f013 100644 --- a/modules/templates/helper.go +++ b/modules/templates/helper.go @@ -341,6 +341,7 @@ func NewFuncMap() []template.FuncMap { "svg": SVG, "avatar": Avatar, "avatarByEmail": AvatarByEmail, + "repoAvatar": RepoAvatar, "SortArrow": func(normSort, revSort, urlSort string, isDefault bool) template.HTML { // if needed if len(normSort) == 0 || len(urlSort) == 0 { @@ -545,23 +546,25 @@ func SVG(icon string, others ...interface{}) template.HTML { return template.HTML("") } -// Avatar renders user and repo avatars. args: user/repo, size (int), class (string) -func Avatar(item interface{}, 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...) - if user, ok := item.(*models.User); ok { - src := user.RealSizedAvatarLink(size * 2) // request double size for finer rendering - if src != "" { - return avatarHTML(src, size, class, user.DisplayName()) - } - } - if repo, ok := item.(*models.Repository); ok { - src := repo.RelAvatarLink() - if src != "" { - return avatarHTML(src, size, class, repo.FullName()) - } + src := user.RealSizedAvatarLink(size * 2) // request double size for finer rendering + if src != "" { + 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...) + src := repo.RelAvatarLink() + if src != "" { + return avatarHTML(src, size, class, repo.FullName()) + } return template.HTML("") } |