Skip to content

Commit f4a1cf7

Browse files
authored
Fix repo home UI when there is no repo description (#30552)
Fix #30502 by a new approach. ![image](https://github.com/go-gitea/gitea/assets/2114189/22f48bca-82d1-45cc-b1b7-ee2344b81a76)
1 parent 1e48677 commit f4a1cf7

File tree

4 files changed

+17
-55
lines changed

4 files changed

+17
-55
lines changed

options/locale/locale_en-US.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1193,7 +1193,6 @@ action.blocked_user = Cannot perform action because you are blocked by the repos
11931193
download_archive = Download Repository
11941194
more_operations = More Operations
11951195
1196-
no_desc = No Description
11971196
quick_guide = Quick Guide
11981197
clone_this_repo = Clone this repository
11991198
cite_this_repo = Cite this repository

templates/repo/home.tmpl

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,10 @@
55
{{template "base/alert" .}}
66
{{template "repo/code/recently_pushed_new_branches" .}}
77
{{if and (not .HideRepoInfo) (not .IsBlame)}}
8-
<div class="repo-description">
9-
<div id="repo-desc" class="gt-word-break tw-text-16">
10-
{{$description := .Repository.DescriptionHTML $.Context}}
11-
{{if $description}}<span class="description">{{$description | RenderCodeBlock}}</span>{{else if .IsRepositoryAdmin}}<span class="no-description text-italic">{{ctx.Locale.Tr "repo.no_desc"}}</span>{{end}}
12-
<a class="link" href="{{.Repository.Website}}">{{.Repository.Website}}</a>
13-
</div>
14-
<form class="ignore-dirty" action="{{.RepoLink}}/search" method="get">
15-
<div class="ui small action input">
16-
<input name="q" value="{{.Keyword}}" placeholder="{{ctx.Locale.Tr "search.code_kind"}}">
17-
{{template "shared/search/button"}}
18-
</div>
19-
</form>
8+
<div class="repo-description gt-word-break">
9+
{{- $description := .Repository.DescriptionHTML ctx -}}
10+
{{if $description}}{{$description | RenderCodeBlock}}{{end}}
11+
{{if .Repository.Website}}<a href="{{.Repository.Website}}">{{.Repository.Website}}</a>{{end}}
2012
</div>
2113
<div class="tw-flex tw-items-center tw-flex-wrap tw-gap-2 tw-my-2" id="repo-topics">
2214
{{/* it should match the code in issue-home.js */}}
@@ -54,7 +46,7 @@
5446
{{$l := Eval $n "-" 1}}
5547
{{$isHomepage := (eq $n 0)}}
5648
<div class="repo-button-row">
57-
<div class="tw-flex tw-items-center tw-gap-y-2">
49+
<div class="tw-flex tw-items-center tw-flex-wrap tw-gap-y-2">
5850
{{template "repo/branch_dropdown" dict "root" . "ContainerClasses" "tw-mr-1"}}
5951
{{if and .CanCompareOrPull .IsViewBranch (not .Repository.IsArchived)}}
6052
{{$cmpBranch := ""}}
@@ -111,6 +103,13 @@
111103
{{- end -}}
112104
</span>
113105
{{end}}
106+
107+
<form class="ignore-dirty" action="{{.RepoLink}}/search" method="get">
108+
<div class="ui small action input">
109+
<input name="q" value="{{.Keyword}}" placeholder="{{ctx.Locale.Tr "search.code_kind"}}">
110+
{{template "shared/search/button"}}
111+
</div>
112+
</form>
114113
</div>
115114
<div class="tw-flex tw-items-center">
116115
<!-- Only show clone panel in repository home page -->

tests/integration/repo_test.go

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,9 @@ func TestViewRepo(t *testing.T) {
2828
resp := session.MakeRequest(t, req, http.StatusOK)
2929

3030
htmlDoc := NewHTMLParser(t, resp.Body)
31-
noDescription := htmlDoc.doc.Find("#repo-desc").Children()
3231
repoTopics := htmlDoc.doc.Find("#repo-topics").Children()
3332
repoSummary := htmlDoc.doc.Find(".repository-summary").Children()
3433

35-
assert.True(t, noDescription.HasClass("no-description"))
3634
assert.True(t, repoTopics.HasClass("repo-topic"))
3735
assert.True(t, repoSummary.HasClass("repository-menu"))
3836

@@ -177,30 +175,6 @@ func TestViewRepoWithSymlinks(t *testing.T) {
177175
assert.Equal(t, "link_link: svg octicon-file-symlink-file", items[4])
178176
}
179177

180-
// TestViewAsRepoAdmin tests PR #2167
181-
func TestViewAsRepoAdmin(t *testing.T) {
182-
for user, expectedNoDescription := range map[string]bool{
183-
"user2": true,
184-
"user4": false,
185-
} {
186-
defer tests.PrepareTestEnv(t)()
187-
188-
session := loginUser(t, user)
189-
190-
req := NewRequest(t, "GET", "/user2/repo1.git")
191-
resp := session.MakeRequest(t, req, http.StatusOK)
192-
193-
htmlDoc := NewHTMLParser(t, resp.Body)
194-
noDescription := htmlDoc.doc.Find("#repo-desc").Children()
195-
repoTopics := htmlDoc.doc.Find("#repo-topics").Children()
196-
repoSummary := htmlDoc.doc.Find(".repository-summary").Children()
197-
198-
assert.Equal(t, expectedNoDescription, noDescription.HasClass("no-description"))
199-
assert.True(t, repoTopics.HasClass("repo-topic"))
200-
assert.True(t, repoSummary.HasClass("repository-menu"))
201-
}
202-
}
203-
204178
// TestViewFileInRepo repo description, topics and summary should not be displayed when viewing a file
205179
func TestViewFileInRepo(t *testing.T) {
206180
defer tests.PrepareTestEnv(t)()
@@ -211,7 +185,7 @@ func TestViewFileInRepo(t *testing.T) {
211185
resp := session.MakeRequest(t, req, http.StatusOK)
212186

213187
htmlDoc := NewHTMLParser(t, resp.Body)
214-
description := htmlDoc.doc.Find("#repo-desc")
188+
description := htmlDoc.doc.Find(".repo-description")
215189
repoTopics := htmlDoc.doc.Find("#repo-topics")
216190
repoSummary := htmlDoc.doc.Find(".repository-summary")
217191

@@ -230,7 +204,7 @@ func TestBlameFileInRepo(t *testing.T) {
230204
resp := session.MakeRequest(t, req, http.StatusOK)
231205

232206
htmlDoc := NewHTMLParser(t, resp.Body)
233-
description := htmlDoc.doc.Find("#repo-desc")
207+
description := htmlDoc.doc.Find(".repo-description")
234208
repoTopics := htmlDoc.doc.Find("#repo-topics")
235209
repoSummary := htmlDoc.doc.Find(".repository-summary")
236210

@@ -249,7 +223,7 @@ func TestViewRepoDirectory(t *testing.T) {
249223
resp := session.MakeRequest(t, req, http.StatusOK)
250224

251225
htmlDoc := NewHTMLParser(t, resp.Body)
252-
description := htmlDoc.doc.Find("#repo-desc")
226+
description := htmlDoc.doc.Find(".repo-description")
253227
repoTopics := htmlDoc.doc.Find("#repo-topics")
254228
repoSummary := htmlDoc.doc.Find(".repository-summary")
255229

web_src/css/repo.css

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -157,21 +157,11 @@
157157
left: auto !important;
158158
}
159159

160-
.repository.file.list .repo-description {
161-
display: flex;
162-
justify-content: space-between;
163-
align-items: center;
164-
gap: 5px;
160+
.repository .repo-description {
161+
font-size: 16px;
165162
margin-bottom: 5px;
166163
}
167164

168-
@media (max-width: 767.98px) {
169-
.repository.file.list .repo-description {
170-
flex-direction: column;
171-
align-items: stretch;
172-
}
173-
}
174-
175165
.commit-summary {
176166
flex: 1;
177167
overflow-wrap: anywhere;

0 commit comments

Comments
 (0)