From 35d21b2712a8ef6f000e0cb4dba9c9f0223f81b7 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Mon, 6 Nov 2023 08:52:49 +0000 Subject: [PATCH 01/34] first change --- modules/context/repo.go | 10 + options/locale/locale_en-US.ini | 7 + routers/web/repo/view.go | 1 + templates/repo/home.tmpl | 278 +++++++++++++------------- templates/repo/sidebar/repo_info.tmpl | 60 ++++++ web_src/css/repo.css | 49 +++++ 6 files changed, 267 insertions(+), 138 deletions(-) create mode 100644 templates/repo/sidebar/repo_info.tmpl diff --git a/modules/context/repo.go b/modules/context/repo.go index 9efa2ab3c0827..adffe0b1c61b6 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -553,6 +553,16 @@ func RepoAssignment(ctx *Context) context.CancelFunc { ctx.ServerError("GetReleaseCountByRepoID", err) return nil } + release, err := repo_model.GetLatestReleaseByRepoID(ctx, ctx.Repo.Repository.ID) + if err != nil { + ctx.ServerError("GetLatestReleaseByRepoID", err) + return nil + } + if err = release.LoadAttributes(ctx); err != nil { + ctx.ServerError("release.LoadAttributes", err) + return nil + } + ctx.Data["LatestRelease"] = release ctx.Data["Title"] = owner.Name + "/" + repo.Name ctx.Data["Repository"] = repo diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index a7a7a4f4c50f9..2aab3e525e80c 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1053,6 +1053,13 @@ form.reach_limit_of_creation_n = The owner has already reached the limit of %d r form.name_reserved = The repository name "%s" is reserved. form.name_pattern_not_allowed = The pattern "%s" is not allowed in a repository name. +sidebar.readme = Readme +sidebar.stars = stars +sidebar.forks = forks +sidebar.watching = watching +sidebar.contributors = Contributors +latest_release = Latest + need_auth = Authorization migrate_options = Migration Options migrate_service = Migration Service diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index 4dfa01d8e2a73..38082a4e3a59b 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -1026,6 +1026,7 @@ func renderCode(ctx *context.Context) { } ctx.Data["Paths"] = paths + ctx.Data["IsHomePage"] = len(paths) == 0 ctx.Data["TreeLink"] = treeLink ctx.Data["TreeNames"] = treeNames ctx.Data["BranchLink"] = branchLink diff --git a/templates/repo/home.tmpl b/templates/repo/home.tmpl index d3f0ead729999..20c4af36f0684 100644 --- a/templates/repo/home.tmpl +++ b/templates/repo/home.tmpl @@ -4,54 +4,6 @@
{{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}} -
- {{if .RepoSearchEnabled}} - - {{end}} -
-
- {{range .Topics}}{{.Name}}{{end}} - {{if and .Permission.IsAdmin (not .Repository.IsArchived)}}{{end}} -
- {{end}} - {{if and .Permission.IsAdmin (not .Repository.IsArchived)}} -
-
- -
-
- - -
-
- {{end}} {{if .Repository.IsArchived}}
{{if .Repository.ArchivedUnix.IsZero}} @@ -61,105 +13,155 @@ {{end}}
{{end}} - {{template "repo/sub_menu" .}} -
-
- {{template "repo/branch_dropdown" dict "root" . "ContainerClasses" "gt-mr-2"}} - {{if and .CanCompareOrPull .IsViewBranch (not .Repository.IsArchived)}} - {{$cmpBranch := ""}} - {{if ne .Repository.ID .BaseRepo.ID}} - {{$cmpBranch = printf "%s/%s:" (.Repository.OwnerName|PathEscape) (.Repository.Name|PathEscape)}} - {{end}} - {{$cmpBranch = print $cmpBranch (.BranchName|PathEscapeSegments)}} - {{$compareLink := printf "%s/compare/%s...%s" .BaseRepo.Link (.BaseRepo.DefaultBranch|PathEscapeSegments) $cmpBranch}} - - {{svg "octicon-git-pull-request"}} - - {{end}} - - {{$n := len .TreeNames}} - {{$l := Eval $n "-" 1}} - {{if eq $n 0}} - {{ctx.Locale.Tr "repo.find_file.go_to_file"}} - {{end}} - - {{if and .CanWriteCode .IsViewBranch (not .Repository.IsMirror) (not .Repository.IsArchived) (not .IsViewFile)}} - - {{end}} + {{end}} + + {{$n := len .TreeNames}} + {{$l := Eval $n "-" 1}} + {{if eq $n 0}} + {{ctx.Locale.Tr "repo.find_file.go_to_file"}} + {{end}} - {{if and (eq $n 0) (.Repository.IsTemplate)}} - - {{ctx.Locale.Tr "repo.use_template"}} - - {{end}} - {{if ne $n 0}} - - {{StringUtils.EllipsisString .Repository.Name 30}} - {{- range $i, $v := .TreeNames -}} - / - {{- if eq $i $l -}} - {{StringUtils.EllipsisString $v 30}} - {{- else -}} - {{$p := index $.Paths $i}}{{StringUtils.EllipsisString $v 30}} - {{- end -}} - {{- end -}} - - {{end}} -
-
- - {{if eq $n 0}} -
- {{template "repo/clone_buttons" .}} - + {{end}} + + {{if and (eq $n 0) (.Repository.IsTemplate)}} + + {{ctx.Locale.Tr "repo.use_template"}} + + {{end}} + {{if ne $n 0}} + + {{StringUtils.EllipsisString .Repository.Name 30}} + {{- range $i, $v := .TreeNames -}} + / + {{- if eq $i $l -}} + {{StringUtils.EllipsisString $v 30}} + {{- else -}} + {{$p := index $.Paths $i}}{{StringUtils.EllipsisString $v 30}} + {{- end -}} + {{- end -}} + + {{end}} +
+
+ + {{if eq $n 0}} +
+ {{template "repo/clone_buttons" .}} + + {{template "repo/clone_script" .}}{{/* the script will update `.js-clone-url` and related elements */}}
- - {{template "repo/clone_script" .}}{{/* the script will update `.js-clone-url` and related elements */}} + {{template "repo/cite/cite_modal" .}} + {{end}} + {{if and (ne $n 0) (not .IsViewFile) (not .IsBlame)}} + + {{svg "octicon-history" 16 "gt-mr-3"}}{{ctx.Locale.Tr "repo.file_history"}} + + {{end}}
- {{template "repo/cite/cite_modal" .}} - {{end}} - {{if and (ne $n 0) (not .IsViewFile) (not .IsBlame)}} - - {{svg "octicon-history" 16 "gt-mr-3"}}{{ctx.Locale.Tr "repo.file_history"}} - +
+ {{if .IsViewFile}} + {{template "repo/view_file" .}} + {{else if .IsBlame}} + {{template "repo/blame" .}} + {{else}} + {{template "repo/view_list" .}} {{end}}
+ +
+
+ {{template "repo/sidebar/repo_info" .}} + +
+
+ {{if .ReadmeExist}} + + {{end}} +
+ {{svg "octicon-star"}}{{CountFmt .Repository.NumStars}} {{ctx.Locale.Tr "repo.sidebar.stars"}} +
+
+ {{svg "octicon-repo-forked"}}{{CountFmt .Repository.NumForks}} {{ctx.Locale.Tr "repo.sidebar.forks"}} +
+
+ {{svg "octicon-eye"}}{{CountFmt .Repository.NumWatches}} {{ctx.Locale.Tr "repo.sidebar.watching"}} +
+
+
+ + {{if .LatestRelease}} +
+
+
+ + {{ctx.Locale.Tr "repo.releases"}} + + {{CountFmt .NumReleases}} +
+
+ + {{svg "octicon-tag" 16 "gt-mr-2"}}{{.LatestRelease.TagName}} + + {{ctx.Locale.Tr "repo.latest_release"}} +
+
+
+ {{end}} +
+
- {{if .IsViewFile}} - {{template "repo/view_file" .}} - {{else if .IsBlame}} - {{template "repo/blame" .}} - {{else}} - {{template "repo/view_list" .}} - {{end}} {{template "base/footer" .}} diff --git a/templates/repo/sidebar/repo_info.tmpl b/templates/repo/sidebar/repo_info.tmpl new file mode 100644 index 0000000000000..e02d614140312 --- /dev/null +++ b/templates/repo/sidebar/repo_info.tmpl @@ -0,0 +1,60 @@ +{{if and (not .HideRepoInfo) (not .IsBlame)}} +
+
+
+ {{ctx.Locale.Tr "repo.repo_desc"}} +
+
+
+
+ {{$description := .Repository.DescriptionHTML $.Context}} + {{if $description}}{{$description | RenderCodeBlock}}{{else if .IsRepositoryAdmin}}{{ctx.Locale.Tr "repo.no_desc"}}{{end}} + {{.Repository.Website}} +
+ + {{if .RepoSearchEnabled}} + + {{end}} +
+
+
+
+ {{range .Topics}}{{.Name}}{{end}} + {{if and .Permission.IsAdmin (not .Repository.IsArchived)}}{{end}} +
+ {{if and .Permission.IsAdmin (not .Repository.IsArchived)}} +
+
+ +
+
+ + +
+
+ {{end}} +
+
+
+{{end}} \ No newline at end of file diff --git a/web_src/css/repo.css b/web_src/css/repo.css index e4995d42298b6..0179c4472690b 100644 --- a/web_src/css/repo.css +++ b/web_src/css/repo.css @@ -106,6 +106,51 @@ white-space: nowrap; } +.repo-content { + display: flex; + align-items: flex-start; + gap: 16px; +} + +@media (max-width: 767.98px) { + .repo-content { + flex-direction: column; + } +} + +.repo-content-main[data-home="true"] { + margin: 0 !important; + width: calc(100% - 316px); +} + +.repo-content-main[data-home="false"] { + margin: 0 !important; + width: 100%; +} + +@media (max-width: 767.98px) { + .repo-content-main[data-home="true"] { + margin: 0 !important; + width: 100%; + } +} + +.repo-content-sidebar[data-home="true"] { + margin: 0 !important; + width: 300px; +} + +.repo-content-sidebar[data-home="false"] { + display: none; +} + +@media (max-width: 767.98px) { + .repo-content-sidebar[data-home="true"] { + margin: 0 !important; + width: 100%; + } +} + .repository .header-wrapper { background-color: var(--color-header-wrapper); } @@ -3140,3 +3185,7 @@ tbody.commit-list { #cherry-pick-modal .scrolling.menu { max-height: 200px; } + +#repo-desc .description { + max-height: 150px; +} From e688cfd6d1ee9cacb91822afcf0ae64d55d22431 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Mon, 6 Nov 2023 08:58:09 +0000 Subject: [PATCH 02/34] fix 500 error in empty repo --- modules/context/repo.go | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/modules/context/repo.go b/modules/context/repo.go index adffe0b1c61b6..9252f2fc48a33 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -545,7 +545,7 @@ func RepoAssignment(ctx *Context) context.CancelFunc { ctx.ServerError("GetReleaseCountByRepoID", err) return nil } - ctx.Data["NumReleases"], err = repo_model.GetReleaseCountByRepoID(ctx, ctx.Repo.Repository.ID, repo_model.FindReleasesOptions{ + numReleases, err := repo_model.GetReleaseCountByRepoID(ctx, ctx.Repo.Repository.ID, repo_model.FindReleasesOptions{ // only show draft releases for users who can write, read-only users shouldn't see draft releases. IncludeDrafts: ctx.Repo.CanWrite(unit_model.TypeReleases), }) @@ -553,16 +553,20 @@ func RepoAssignment(ctx *Context) context.CancelFunc { ctx.ServerError("GetReleaseCountByRepoID", err) return nil } - release, err := repo_model.GetLatestReleaseByRepoID(ctx, ctx.Repo.Repository.ID) - if err != nil { - ctx.ServerError("GetLatestReleaseByRepoID", err) - return nil - } - if err = release.LoadAttributes(ctx); err != nil { - ctx.ServerError("release.LoadAttributes", err) - return nil + ctx.Data["NumReleases"] = numReleases + + if numReleases > 0 { + release, err := repo_model.GetLatestReleaseByRepoID(ctx, ctx.Repo.Repository.ID) + if err != nil { + ctx.ServerError("GetLatestReleaseByRepoID", err) + return nil + } + if err = release.LoadAttributes(ctx); err != nil { + ctx.ServerError("release.LoadAttributes", err) + return nil + } + ctx.Data["LatestRelease"] = release } - ctx.Data["LatestRelease"] = release ctx.Data["Title"] = owner.Name + "/" + repo.Name ctx.Data["Repository"] = repo From f1f0647e1ec030b4b8301c934c2a3e2c6a418431 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Tue, 7 Nov 2023 09:11:11 +0900 Subject: [PATCH 03/34] Update templates/repo/sidebar/repo_info.tmpl Co-authored-by: silverwind --- templates/repo/sidebar/repo_info.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/repo/sidebar/repo_info.tmpl b/templates/repo/sidebar/repo_info.tmpl index e02d614140312..fe8ea4b11a8c0 100644 --- a/templates/repo/sidebar/repo_info.tmpl +++ b/templates/repo/sidebar/repo_info.tmpl @@ -57,4 +57,4 @@ -{{end}} \ No newline at end of file +{{end}} From 7b27f1f83fdb3c3e25557124f90db5635e83234d Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Tue, 7 Nov 2023 05:29:08 +0000 Subject: [PATCH 04/34] fix conflicts come from #27925 --- templates/repo/sidebar/repo_info.tmpl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/repo/sidebar/repo_info.tmpl b/templates/repo/sidebar/repo_info.tmpl index fe8ea4b11a8c0..b33f4539c9db6 100644 --- a/templates/repo/sidebar/repo_info.tmpl +++ b/templates/repo/sidebar/repo_info.tmpl @@ -37,9 +37,9 @@ {{if and .Permission.IsAdmin (not .Repository.IsArchived)}}{{end}} {{if and .Permission.IsAdmin (not .Repository.IsArchived)}} -
-
- @@ -119,18 +116,6 @@