Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions templates/repo/commit_author.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{{/* Template Attributes:
* User: The user associated with the commit, if any
* Commit: The commit
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you should pass so many different structs.

Commit is not really used. What you need is a "git user" or "gitea user".

Copy link
Member Author

@silverwind silverwind Dec 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit is used for .Commit.Author vs .Author. Maybe it can be unified, not sure. The three pages all pass different context variables.

* Author: The author, currently only the commit page passes this
* AvatarSize: Avatar size in pixels
* AuthorBold: Whether to render the autor as bold text
* IsSigned: Whether the user is currently signed in
*/}}
<div class="flex-text-inline{{if .AuthorBold}} tw-font-semibold{{end}}">
{{if .User}}
{{ctx.AvatarUtils.Avatar .User .AvatarSize}}
{{$username := ""}}
{{if and .User.FullName DefaultShowFullName}}
{{$username = .User.FullName}}
{{else if .User.Name}}
{{$username = .User.Name}}
{{end}}
Comment on lines +13 to +17
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image image

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if *User will also be compatible with .Author.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if *User will also be compatible with .Author.

No. More complicated.

<a class="muted author-wrapper" href="{{.User.HomeLink}}" data-tooltip-content="{{$username}}">
{{$username}}
</a>
{{else if .Author}}
{{$username := ""}}
{{if and .Author.FullName DefaultShowFullName}}
{{$username = .Author.FullName}}
{{else if .Author.Name}}
{{$username = .Author.Name}}
{{else if .Commit.Author.Name}}
{{$username = .Commit.Author.Name}}
{{end}}
{{ctx.AvatarUtils.AvatarByEmail .Author.Email $username .AvatarSize}}
<span{{if .IsSigned}} title="{{.Author.Email}}"{{end}}>
{{if .Author.HomeLink}}
<a class="muted author-wrapper" href="{{.Author.HomeLink}}">
{{$username}}
</a>
{{else}}
{{$username}}
{{end}}
</span>
{{else}}
{{$username := ""}}
{{if .Commit.Author.Name}}
{{$username = .Commit.Author.Name}}
{{else}}
{{$username = .Author.Name}}
{{end}}
{{ctx.AvatarUtils.AvatarByEmail .Commit.Author.Email $username .AvatarSize}}
<span{{if .IsSigned}} title="{{.Commit.Author.Email}}"{{end}}>
{{if .Commit.Author.Name}}
{{.Commit.Author.Name}}
{{else}}
{{.Author.Name}}
{{end}}
</span>
{{end}}
</div>
20 changes: 7 additions & 13 deletions templates/repo/commit_page.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,13 @@
</div>

<div class="ui bottom attached segment flex-text-block tw-flex-wrap">
<div class="flex-text-inline">
{{if .Author}}
{{ctx.AvatarUtils.Avatar .Author 20}}
{{if .Author.FullName}}
<a href="{{.Author.HomeLink}}"><strong>{{.Author.FullName}}</strong></a>
{{else}}
<a href="{{.Author.HomeLink}}"><strong>{{.Commit.Author.Name}}</strong></a>
{{end}}
{{else}}
{{ctx.AvatarUtils.AvatarByEmail .Commit.Author.Email .Commit.Author.Email 20}}
<strong>{{.Commit.Author.Name}}</strong>
{{end}}
</div>
{{template "repo/commit_author" (dict
"Commit" .Commit
"Author" .Author
"AvatarSize" 20
"AuthorBold" true
"IsSigned" $.IsSigned
)}}

<span class="text grey">{{DateUtils.TimeSince .Commit.Author.When}}</span>

Expand Down
16 changes: 6 additions & 10 deletions templates/repo/commits_list.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,12 @@
<tr>
<td class="author">
<div class="tw-flex">
{{$userName := .Author.Name}}
{{if .User}}
{{if and .User.FullName DefaultShowFullName}}
{{$userName = .User.FullName}}
{{end}}
{{ctx.AvatarUtils.Avatar .User 28 "tw-mr-2"}}<a class="muted author-wrapper" href="{{.User.HomeLink}}">{{$userName}}</a>
{{else}}
{{ctx.AvatarUtils.AvatarByEmail .Author.Email .Author.Name 28 "tw-mr-2"}}
<span class="author-wrapper">{{$userName}}</span>
{{end}}
{{template "repo/commit_author" (dict
"Commit" .
"User" .User
"AvatarSize" 28
"IsSigned" $.IsSigned
)}}
</div>
</td>
<td class="sha">
Expand Down
21 changes: 7 additions & 14 deletions templates/repo/latest_commit.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,13 @@
{{if not .LatestCommit}}
{{else}}
{{if .LatestCommitUser}}
{{ctx.AvatarUtils.Avatar .LatestCommitUser 24}}
{{if and .LatestCommitUser.FullName DefaultShowFullName}}
<a class="muted author-wrapper" title="{{.LatestCommitUser.FullName}}" href="{{.LatestCommitUser.HomeLink}}"><strong>{{.LatestCommitUser.FullName}}</strong></a>
{{else}}
<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>
{{end}}
{{else}}
{{if .LatestCommit.Author}}
{{ctx.AvatarUtils.AvatarByEmail .LatestCommit.Author.Email .LatestCommit.Author.Name 24}}
<span class="author-wrapper" title="{{.LatestCommit.Author.Name}}"><strong>{{.LatestCommit.Author.Name}}</strong></span>
{{end}}
{{end}}

{{template "repo/commit_author" (dict
"User" .LatestCommitUser
"Commit" .LatestCommit
"AvatarSize" 24
"AuthorBold" true
"IsSigned" $.IsSigned
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to pass "IsSigned"

Use ctx.RootData.IsSigned

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, didn't know that existed.

)}}
{{template "repo/commit_sign_badge" dict "Commit" .LatestCommit "CommitBaseLink" (print .RepoLink "/commit") "CommitSignVerification" .LatestCommitVerification}}

{{template "repo/commit_statuses" dict "Status" .LatestCommitStatus "Statuses" .LatestCommitStatuses}}
Expand Down
Loading