From f4a1cf7eab674e3c1589a7ecef015ff64e441946 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Mon, 22 Apr 2024 07:47:31 +0800 Subject: [PATCH] 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) --- options/locale/locale_en-US.ini | 1 - templates/repo/home.tmpl | 25 ++++++++++++------------- tests/integration/repo_test.go | 32 +++----------------------------- web_src/css/repo.css | 14 ++------------ 4 files changed, 17 insertions(+), 55 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index c602aba53..c7d99a85b 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1193,7 +1193,6 @@ action.blocked_user = Cannot perform action because you are blocked by the repos download_archive = Download Repository more_operations = More Operations -no_desc = No Description quick_guide = Quick Guide clone_this_repo = Clone this repository cite_this_repo = Cite this repository diff --git a/templates/repo/home.tmpl b/templates/repo/home.tmpl index e18a0aec1..7b37ac101 100644 --- a/templates/repo/home.tmpl +++ b/templates/repo/home.tmpl @@ -5,18 +5,10 @@ {{template "base/alert" .}} {{template "repo/code/recently_pushed_new_branches" .}} {{if and (not .HideRepoInfo) (not .IsBlame)}} -
-
- {{$description := .Repository.DescriptionHTML $.Context}} - {{if $description}}{{$description | RenderCodeBlock}}{{else if .IsRepositoryAdmin}}{{ctx.Locale.Tr "repo.no_desc"}}{{end}} - {{.Repository.Website}} -
-
-
- - {{template "shared/search/button"}} -
-
+
+ {{- $description := .Repository.DescriptionHTML ctx -}} + {{if $description}}{{$description | RenderCodeBlock}}{{end}} + {{if .Repository.Website}}{{.Repository.Website}}{{end}}
{{/* it should match the code in issue-home.js */}} @@ -54,7 +46,7 @@ {{$l := Eval $n "-" 1}} {{$isHomepage := (eq $n 0)}}
-
+
{{template "repo/branch_dropdown" dict "root" . "ContainerClasses" "tw-mr-1"}} {{if and .CanCompareOrPull .IsViewBranch (not .Repository.IsArchived)}} {{$cmpBranch := ""}} @@ -111,6 +103,13 @@ {{- end -}} {{end}} + +
+
+ + {{template "shared/search/button"}} +
+
diff --git a/tests/integration/repo_test.go b/tests/integration/repo_test.go index 06c55b1e8..b967ccad1 100644 --- a/tests/integration/repo_test.go +++ b/tests/integration/repo_test.go @@ -28,11 +28,9 @@ func TestViewRepo(t *testing.T) { resp := session.MakeRequest(t, req, http.StatusOK) htmlDoc := NewHTMLParser(t, resp.Body) - noDescription := htmlDoc.doc.Find("#repo-desc").Children() repoTopics := htmlDoc.doc.Find("#repo-topics").Children() repoSummary := htmlDoc.doc.Find(".repository-summary").Children() - assert.True(t, noDescription.HasClass("no-description")) assert.True(t, repoTopics.HasClass("repo-topic")) assert.True(t, repoSummary.HasClass("repository-menu")) @@ -177,30 +175,6 @@ func TestViewRepoWithSymlinks(t *testing.T) { assert.Equal(t, "link_link: svg octicon-file-symlink-file", items[4]) } -// TestViewAsRepoAdmin tests PR #2167 -func TestViewAsRepoAdmin(t *testing.T) { - for user, expectedNoDescription := range map[string]bool{ - "user2": true, - "user4": false, - } { - defer tests.PrepareTestEnv(t)() - - session := loginUser(t, user) - - req := NewRequest(t, "GET", "/user2/repo1.git") - resp := session.MakeRequest(t, req, http.StatusOK) - - htmlDoc := NewHTMLParser(t, resp.Body) - noDescription := htmlDoc.doc.Find("#repo-desc").Children() - repoTopics := htmlDoc.doc.Find("#repo-topics").Children() - repoSummary := htmlDoc.doc.Find(".repository-summary").Children() - - assert.Equal(t, expectedNoDescription, noDescription.HasClass("no-description")) - assert.True(t, repoTopics.HasClass("repo-topic")) - assert.True(t, repoSummary.HasClass("repository-menu")) - } -} - // TestViewFileInRepo repo description, topics and summary should not be displayed when viewing a file func TestViewFileInRepo(t *testing.T) { defer tests.PrepareTestEnv(t)() @@ -211,7 +185,7 @@ func TestViewFileInRepo(t *testing.T) { resp := session.MakeRequest(t, req, http.StatusOK) htmlDoc := NewHTMLParser(t, resp.Body) - description := htmlDoc.doc.Find("#repo-desc") + description := htmlDoc.doc.Find(".repo-description") repoTopics := htmlDoc.doc.Find("#repo-topics") repoSummary := htmlDoc.doc.Find(".repository-summary") @@ -230,7 +204,7 @@ func TestBlameFileInRepo(t *testing.T) { resp := session.MakeRequest(t, req, http.StatusOK) htmlDoc := NewHTMLParser(t, resp.Body) - description := htmlDoc.doc.Find("#repo-desc") + description := htmlDoc.doc.Find(".repo-description") repoTopics := htmlDoc.doc.Find("#repo-topics") repoSummary := htmlDoc.doc.Find(".repository-summary") @@ -249,7 +223,7 @@ func TestViewRepoDirectory(t *testing.T) { resp := session.MakeRequest(t, req, http.StatusOK) htmlDoc := NewHTMLParser(t, resp.Body) - description := htmlDoc.doc.Find("#repo-desc") + description := htmlDoc.doc.Find(".repo-description") repoTopics := htmlDoc.doc.Find("#repo-topics") repoSummary := htmlDoc.doc.Find(".repository-summary") diff --git a/web_src/css/repo.css b/web_src/css/repo.css index 6884bc5b1..62a72abaf 100644 --- a/web_src/css/repo.css +++ b/web_src/css/repo.css @@ -157,21 +157,11 @@ left: auto !important; } -.repository.file.list .repo-description { - display: flex; - justify-content: space-between; - align-items: center; - gap: 5px; +.repository .repo-description { + font-size: 16px; margin-bottom: 5px; } -@media (max-width: 767.98px) { - .repository.file.list .repo-description { - flex-direction: column; - align-items: stretch; - } -} - .commit-summary { flex: 1; overflow-wrap: anywhere;