From 78b2a1cc3689e1b7555bd874763eea7eb28982f9 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Tue, 8 Aug 2023 15:29:35 +0800 Subject: [PATCH] Remove unnecessary template helper repoAvatar (#26387) And simplify the "repo/icon" code --- modules/templates/helper.go | 1 - modules/templates/util_avatar.go | 11 ----------- templates/explore/repo_list.tmpl | 7 +------ templates/org/team/repositories.tmpl | 7 +------ templates/repo/header.tmpl | 11 +++-------- templates/repo/icon.tmpl | 21 +++++++++++---------- 6 files changed, 16 insertions(+), 42 deletions(-) diff --git a/modules/templates/helper.go b/modules/templates/helper.go index cfcfbbed3..30ca767ca 100644 --- a/modules/templates/helper.go +++ b/modules/templates/helper.go @@ -59,7 +59,6 @@ func NewFuncMap() template.FuncMap { "avatarHTML": AvatarHTML, "avatarByAction": AvatarByAction, "avatarByEmail": AvatarByEmail, - "repoAvatar": RepoAvatar, "EntryIcon": base.EntryIcon, "MigrationIcon": MigrationIcon, "ActionIcon": ActionIcon, diff --git a/modules/templates/util_avatar.go b/modules/templates/util_avatar.go index 9f8f8f87a..81961041a 100644 --- a/modules/templates/util_avatar.go +++ b/modules/templates/util_avatar.go @@ -60,17 +60,6 @@ func AvatarByAction(ctx context.Context, action *activities_model.Action, others return Avatar(ctx, action.ActUser, others...) } -// RepoAvatar renders repo avatars. args: repo, size(int), class (string) -func RepoAvatar(repo *repo_model.Repository, others ...any) template.HTML { - size, class := gitea_html.ParseSizeAndClass(avatars.DefaultAvatarPixelSize, avatars.DefaultAvatarClass, others...) - - src := repo.RelAvatarLink() - if src != "" { - 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(ctx context.Context, email, name string, others ...any) template.HTML { size, class := gitea_html.ParseSizeAndClass(avatars.DefaultAvatarPixelSize, avatars.DefaultAvatarClass, others...) diff --git a/templates/explore/repo_list.tmpl b/templates/explore/repo_list.tmpl index 44f790032..260f165b7 100644 --- a/templates/explore/repo_list.tmpl +++ b/templates/explore/repo_list.tmpl @@ -2,12 +2,7 @@ {{range .Repos}}
- {{$avatar := (repoAvatar . 32)}} - {{if $avatar}} - {{$avatar}} - {{else}} - {{template "repo/icon" .}} - {{end}} + {{template "repo/icon" .}}
diff --git a/templates/org/team/repositories.tmpl b/templates/org/team/repositories.tmpl index 698b0a91b..ab5f6c6e7 100644 --- a/templates/org/team/repositories.tmpl +++ b/templates/org/team/repositories.tmpl @@ -30,12 +30,7 @@ {{range .Team.Repos}}
- {{$avatar := (repoAvatar . 32)}} - {{if $avatar}} - {{$avatar}} - {{else}} - {{template "repo/icon" .}} - {{end}} + {{template "repo/icon" .}}
diff --git a/templates/repo/header.tmpl b/templates/repo/header.tmpl index 865f3ba4a..984e9f044 100644 --- a/templates/repo/header.tmpl +++ b/templates/repo/header.tmpl @@ -4,14 +4,9 @@
- {{$avatar := (repoAvatar . 32 "gt-mr-3")}} - {{if $avatar}} - {{$avatar}} - {{else}} -
- {{template "repo/icon" .}} -
- {{end}} +
+ {{template "repo/icon" .}} +
{{.Owner.Name}}
/
{{.Name}} diff --git a/templates/repo/icon.tmpl b/templates/repo/icon.tmpl index a37197d42..6c63e6eca 100644 --- a/templates/repo/icon.tmpl +++ b/templates/repo/icon.tmpl @@ -1,15 +1,16 @@
- {{if $.IsTemplate}} + {{$avatarLink := .RelAvatarLink}} + {{if $avatarLink}} + {{.FullName}} + {{else if $.IsTemplate}} {{svg "octicon-repo-template" 32}} + {{else if $.IsPrivate}} + {{svg "octicon-lock" 32}} + {{else if $.IsMirror}} + {{svg "octicon-mirror" 32}} + {{else if $.IsFork}} + {{svg "octicon-repo-forked" 32}} {{else}} - {{if $.IsPrivate}} - {{svg "octicon-lock" 32}} - {{else if $.IsMirror}} - {{svg "octicon-mirror" 32}} - {{else if $.IsFork}} - {{svg "octicon-repo-forked" 32}} - {{else}} - {{svg "octicon-repo" 32}} - {{end}} + {{svg "octicon-repo" 32}} {{end}}