Skip to content

Commit fba7150

Browse files
authored
Refactor "shortsha" (#26877)
The old code used complex `if` blocks and strange HTML layouts. <details> ![image](https://github.com/go-gitea/gitea/assets/2114189/7fbee2b8-d150-4e6b-b67e-83400fa290eb) </details> This PR refactors the template code and remove legacy CSS styles. The UI doesn't change much. ![image](https://github.com/go-gitea/gitea/assets/2114189/3e195df9-0ab5-4182-bcb2-bb20cad823f2) ![image](https://github.com/go-gitea/gitea/assets/2114189/f707a49f-be41-4dfe-871f-2869f2230380)
1 parent f1fe102 commit fba7150

File tree

6 files changed

+16
-93
lines changed

6 files changed

+16
-93
lines changed

templates/repo/commits_list.tmpl

+8-18
Original file line numberDiff line numberDiff line change
@@ -41,28 +41,18 @@
4141
{{$class = (printf "%s%s" $class " isWarning")}}
4242
{{end}}
4343
{{end}}
44+
{{$commitShaLink := ""}}
4445
{{if $.PageIsWiki}}
45-
<a href="{{$commitRepoLink}}/wiki/commit/{{.ID}}" rel="nofollow" class="{{$class}}">
46+
{{$commitShaLink = (printf "%s/wiki/commit/%s" $commitRepoLink (PathEscape .ID.String))}}
4647
{{else if $.PageIsPullCommits}}
47-
<a href="{{$commitRepoLink}}/pulls/{{$.Issue.Index}}/commits/{{.ID}}" rel="nofollow" class="{{$class}}">
48+
{{$commitShaLink = (printf "%s/pulls/%d/commits/%s" $commitRepoLink $.Issue.Index (PathEscape .ID.String))}}
4849
{{else if $.Reponame}}
49-
<a href="{{$commitRepoLink}}/commit/{{.ID}}" rel="nofollow" class="{{$class}}">
50-
{{else}}
51-
<span class="{{$class}}">
50+
{{$commitShaLink = (printf "%s/commit/%s" $commitRepoLink (PathEscape .ID.String))}}
5251
{{end}}
52+
<a {{if $commitShaLink}}href="{{$commitShaLink}}"{{end}} class="{{$class}}">
5353
<span class="shortsha">{{ShortSha .ID.String}}</span>
54-
{{if .Signature}}
55-
{{template "repo/shabox_badge" dict "root" $ "verification" .Verification}}
56-
{{end}}
57-
{{if $.PageIsWiki}}
58-
</a>
59-
{{else if $.PageIsPullCommits}}
60-
</a>
61-
{{else if $.Reponame}}
62-
</a>
63-
{{else}}
64-
</span>
65-
{{end}}
54+
{{if .Signature}}{{template "repo/shabox_badge" dict "root" $ "verification" .Verification}}{{end}}
55+
</a>
6656
</td>
6757
<td class="message">
6858
<span class="message-wrapper">
@@ -78,7 +68,7 @@
7868
{{end}}
7969
{{template "repo/commit_statuses" dict "Status" .Status "Statuses" .Statuses "root" $}}
8070
{{if IsMultilineCommitMessage .Message}}
81-
<pre class="commit-body gt-hidden">{{RenderCommitBody $.Context .Message $commitRepoLink $.Repository.ComposeMetas}}</pre>
71+
<pre class="commit-body gt-m-0 gt-hidden">{{RenderCommitBody $.Context .Message $commitRepoLink $.Repository.ComposeMetas}}</pre>
8272
{{end}}
8373
</td>
8474
{{if .Committer}}

templates/repo/graph/commits.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<a href="{{$.RepoLink}}/commit/{{$commit.Rev|PathEscape}}" rel="nofollow" class="{{$class}}">
2525
<span class="shortsha">{{ShortSha $commit.Commit.ID.String}}</span>
2626
{{- if $commit.Commit.Signature -}}
27-
<span class="shortsha-pad"></span>{{template "repo/shabox_badge" dict "root" $ "verification" $commit.Verification}}
27+
{{template "repo/shabox_badge" dict "root" $ "verification" $commit.Verification}}
2828
{{- end -}}
2929
</a>
3030
</span>

templates/repo/view_list.tmpl

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
<div class="ui active tiny slow centered inline">…</div>
77
{{else}}
88
{{if .LatestCommitUser}}
9-
{{ctx.AvatarUtils.Avatar .LatestCommitUser 24}}
9+
{{ctx.AvatarUtils.Avatar .LatestCommitUser 24 "gt-mr-2"}}
1010
{{if .LatestCommitUser.FullName}}
1111
<a class="muted author-wrapper" title="{{.LatestCommitUser.FullName}}" href="{{.LatestCommitUser.HomeLink}}"><strong>{{.LatestCommitUser.FullName}}</strong></a>
1212
{{else}}
1313
<a class="muted author-wrapper" title="{{if .LatestCommit.Author}}{{.LatestCommit.Author.Name}}{{else}}{{.LatestCommitUser.Name}}{{end}}" href="{{.LatestCommitUser.HomeLink}}"><strong>{{if .LatestCommit.Author}}{{.LatestCommit.Author.Name}}{{else}}{{.LatestCommitUser.Name}}{{end}}</strong></a>
1414
{{end}}
1515
{{else}}
1616
{{if .LatestCommit.Author}}
17-
{{ctx.AvatarUtils.AvatarByEmail .LatestCommit.Author.Email .LatestCommit.Author.Name 24}}
17+
{{ctx.AvatarUtils.AvatarByEmail .LatestCommit.Author.Email .LatestCommit.Author.Name 24 "gt-mr-2"}}
1818
<span class="author-wrapper" title="{{.LatestCommit.Author.Name}}"><strong>{{.LatestCommit.Author.Name}}</strong></span>
1919
{{end}}
2020
{{end}}

web_src/css/base.css

+5-1
Original file line numberDiff line numberDiff line change
@@ -1308,9 +1308,13 @@ img.ui.avatar,
13081308
.ui .sha.label {
13091309
font-family: var(--fonts-monospace);
13101310
font-size: 13px;
1311-
padding: 6px 10px 4px;
13121311
font-weight: var(--font-weight-normal);
13131312
margin: 0 6px;
1313+
padding: 5px 10px;
1314+
}
1315+
1316+
.ui .sha.label .shortsha {
1317+
display: inline-block; /* not sure whether it is still needed */
13141318
}
13151319

13161320
.ui .button.copy-commit-sha {

web_src/css/features/gitgraph.css

-8
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,6 @@
123123
padding-bottom: 3px;
124124
}
125125

126-
#git-graph-container #rev-list .sha.label .shortsha {
127-
padding-top: 0;
128-
}
129-
130-
#git-graph-container #rev-list .sha.label .shortsha-pad {
131-
padding-right: 10px;
132-
}
133-
134126
#git-graph-container #rev-list .sha.label .ui.detail.icon.button {
135127
padding-top: 3px;
136128
margin-top: -5px;

web_src/css/repo.css

-63
Original file line numberDiff line numberDiff line change
@@ -245,15 +245,9 @@
245245
}
246246

247247
.repository.file.list #repo-files-table thead th {
248-
padding-top: 8px;
249-
padding-bottom: 5px;
250248
font-weight: var(--font-weight-normal);
251249
}
252250

253-
.repository.file.list #repo-files-table thead .ui.avatar {
254-
margin-bottom: 5px;
255-
}
256-
257251
.repository.file.list #repo-files-table tbody .svg {
258252
margin-left: 3px;
259253
margin-right: 5px;
@@ -891,11 +885,6 @@
891885
background: var(--color-red-badge-bg);
892886
}
893887

894-
.repository.view.issue .comment-list .timeline-item.commits-list .singular-commit .shabox .sha.label.isSigned.isWarning .shortsha {
895-
display: inline-block;
896-
padding-top: 1px;
897-
}
898-
899888
.repository.view.issue .comment-list .timeline-item.commits-list .singular-commit .shabox .sha.label.isSigned.isWarning:hover {
900889
background: var(--color-red-badge-hover-bg) !important;
901890
}
@@ -905,11 +894,6 @@
905894
background: var(--color-green-badge-bg);
906895
}
907896

908-
.repository.view.issue .comment-list .timeline-item.commits-list .singular-commit .shabox .sha.label.isSigned.isVerified .shortsha {
909-
display: inline-block;
910-
padding-top: 1px;
911-
}
912-
913897
.repository.view.issue .comment-list .timeline-item.commits-list .singular-commit .shabox .sha.label.isSigned.isVerified:hover {
914898
background: var(--color-green-badge-hover-bg) !important;
915899
}
@@ -919,11 +903,6 @@
919903
background: var(--color-yellow-badge-bg);
920904
}
921905

922-
.repository.view.issue .comment-list .timeline-item.commits-list .singular-commit .shabox .sha.label.isSigned.isVerifiedUntrusted .shortsha {
923-
display: inline-block;
924-
padding-top: 1px;
925-
}
926-
927906
.repository.view.issue .comment-list .timeline-item.commits-list .singular-commit .shabox .sha.label.isSigned.isVerifiedUntrusted:hover {
928907
background: var(--color-yellow-badge-hover-bg) !important;
929908
}
@@ -933,11 +912,6 @@
933912
background: var(--color-orange-badge-bg);
934913
}
935914

936-
.repository.view.issue .comment-list .timeline-item.commits-list .singular-commit .shabox .sha.label.isSigned.isVerifiedUnmatched .shortsha {
937-
display: inline-block;
938-
padding-top: 1px;
939-
}
940-
941915
.repository.view.issue .comment-list .timeline-item.commits-list .singular-commit .shabox .sha.label.isSigned.isVerifiedUnmatched:hover {
942916
background: var(--color-orange-badge-hover-bg) !important;
943917
}
@@ -1387,14 +1361,6 @@
13871361
background: var(--color-red-badge-bg);
13881362
}
13891363

1390-
.repository #commits-table td.sha .sha.label.isSigned.isWarning .shortsha,
1391-
.repository #repo-files-table .sha.label.isSigned.isWarning .shortsha,
1392-
.repository #rev-list .sha.label.isSigned.isWarning .shortsha,
1393-
.repository .timeline-item.commits-list .singular-commit .sha.label.isSigned.isWarning .shortsha {
1394-
display: inline-block;
1395-
padding-top: 1px;
1396-
}
1397-
13981364
.repository #commits-table td.sha .sha.label.isSigned.isWarning .detail.icon,
13991365
.repository #repo-files-table .sha.label.isSigned.isWarning .detail.icon,
14001366
.repository #rev-list .sha.label.isSigned.isWarning .detail.icon,
@@ -1418,14 +1384,6 @@
14181384
background: var(--color-green-badge-bg);
14191385
}
14201386

1421-
.repository #commits-table td.sha .sha.label.isSigned.isVerified .shortsha,
1422-
.repository #repo-files-table .sha.label.isSigned.isVerified .shortsha,
1423-
.repository #rev-list .sha.label.isSigned.isVerified .shortsha,
1424-
.repository .timeline-item.commits-list .singular-commit .sha.label.isSigned.isVerified .shortsha {
1425-
display: inline-block;
1426-
padding-top: 1px;
1427-
}
1428-
14291387
.repository #commits-table td.sha .sha.label.isSigned.isVerified .detail.icon,
14301388
.repository #repo-files-table .sha.label.isSigned.isVerified .detail.icon,
14311389
.repository #rev-list .sha.label.isSigned.isVerified .detail.icon,
@@ -1449,14 +1407,6 @@
14491407
background: var(--color-yellow-badge-bg);
14501408
}
14511409

1452-
.repository #commits-table td.sha .sha.label.isSigned.isVerifiedUntrusted .shortsha,
1453-
.repository #repo-files-table .sha.label.isSigned.isVerifiedUntrusted .shortsha,
1454-
.repository #rev-list .sha.label.isSigned.isVerifiedUntrusted .shortsha,
1455-
.repository .timeline-item.commits-list .singular-commit .sha.label.isSigned.isVerifiedUntrusted .shortsha {
1456-
display: inline-block;
1457-
padding-top: 1px;
1458-
}
1459-
14601410
.repository #commits-table td.sha .sha.label.isSigned.isVerifiedUntrusted .detail.icon,
14611411
.repository #repo-files-table .sha.label.isSigned.isVerifiedUntrusted .detail.icon,
14621412
.repository #rev-list .sha.label.isSigned.isVerifiedUntrusted .detail.icon,
@@ -1480,14 +1430,6 @@
14801430
background: var(--color-orange-badge-bg);
14811431
}
14821432

1483-
.repository #commits-table td.sha .sha.label.isSigned.isVerifiedUnmatched .shortsha,
1484-
.repository #repo-files-table .sha.label.isSigned.isVerifiedUnmatched .shortsha,
1485-
.repository #rev-list .sha.label.isSigned.isVerifiedUnmatched .shortsha,
1486-
.repository .timeline-item.commits-list .singular-commit .sha.label.isSigned.isVerifiedUnmatched .shortsha {
1487-
display: inline-block;
1488-
padding-top: 1px;
1489-
}
1490-
14911433
.repository #commits-table td.sha .sha.label.isSigned.isVerifiedUnmatched .detail.icon,
14921434
.repository #repo-files-table .sha.label.isSigned.isVerifiedUnmatched .detail.icon,
14931435
.repository #rev-list .sha.label.isSigned.isVerifiedUnmatched .detail.icon,
@@ -2691,11 +2633,6 @@ tbody.commit-list {
26912633
line-height: initial;
26922634
}
26932635

2694-
/* commit history list */
2695-
.repository:not(.diff) .commit-body {
2696-
margin: 0;
2697-
}
2698-
26992636
/* PR-comment */
27002637
.repository:not(.diff) .timeline-item .commit-body {
27012638
margin-left: 40px;

0 commit comments

Comments
 (0)