From c6668462624a0e4aaafd8a0a3937202fbb34470c Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Tue, 28 Mar 2023 15:32:27 +0800 Subject: [PATCH] fix --- custom/conf/app.example.ini | 10 +++++++--- .../doc/administration/config-cheat-sheet.en-us.md | 4 +++- routers/web/explore/repo.go | 14 +++++++++++--- templates/explore/repo_search.tmpl | 7 +++++-- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/custom/conf/app.example.ini b/custom/conf/app.example.ini index d1cfcd70e585..c25787e72b94 100644 --- a/custom/conf/app.example.ini +++ b/custom/conf/app.example.ini @@ -583,15 +583,15 @@ ROUTER = console ;; * In request Header: X-Request-ID: test-id-123 ;; * Configuration in app.ini: REQUEST_ID_HEADERS = X-Request-ID ;; * Print in log: 127.0.0.1:58384 - - [14/Feb/2023:16:33:51 +0800] "test-id-123" -;; -;; If you configure more than one in the .ini file, it will match in the order of configuration, +;; +;; If you configure more than one in the .ini file, it will match in the order of configuration, ;; and the first match will be finally printed in the log. ;; * E.g: ;; * In reuqest Header: X-Trace-ID: trace-id-1q2w3e4r ;; * Configuration in app.ini: REQUEST_ID_HEADERS = X-Request-ID, X-Trace-ID, X-Req-ID ;; * Print in log: 127.0.0.1:58384 - - [14/Feb/2023:16:33:51 +0800] "trace-id-1q2w3e4r" ;; -;; REQUEST_ID_HEADERS = +;; REQUEST_ID_HEADERS = ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; @@ -1238,6 +1238,10 @@ ROUTER = console ;; ;; Whether to enable a Service Worker to cache frontend assets ;USE_SERVICE_WORKER = false +;; +;; Whether to only show relevant repos on the explore page when no keyword is specified and default sorting is used. +;; A repo is considered irrelevant if it's a fork or if it has no metadata (no description, no icon, no topic). +;ONLY_SHOW_RELEVANT_REPOS = false ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/docs/content/doc/administration/config-cheat-sheet.en-us.md b/docs/content/doc/administration/config-cheat-sheet.en-us.md index 7f31a27f1506..6ffa542e8b95 100644 --- a/docs/content/doc/administration/config-cheat-sheet.en-us.md +++ b/docs/content/doc/administration/config-cheat-sheet.en-us.md @@ -226,11 +226,13 @@ The following configuration set `Content-Type: application/vnd.android.package-a Values can be emoji alias (:smile:) or a unicode emoji. For custom reactions, add a tightly cropped square image to public/img/emoji/reaction_name.png - `CUSTOM_EMOJIS`: **gitea, codeberg, gitlab, git, github, gogs**: Additional Emojis not defined in the utf8 standard. - By default we support Gitea (:gitea:), to add more copy them to public/img/emoji/emoji_name.png and + By default, we support Gitea (:gitea:), to add more copy them to public/img/emoji/emoji_name.png and add it to this config. - `DEFAULT_SHOW_FULL_NAME`: **false**: Whether the full name of the users should be shown where possible. If the full name isn't set, the username will be used. - `SEARCH_REPO_DESCRIPTION`: **true**: Whether to search within description at repository search on explore page. - `USE_SERVICE_WORKER`: **false**: Whether to enable a Service Worker to cache frontend assets. +- `ONLY_SHOW_RELEVANT_REPOS`: **false** Whether to only show relevant repos on the explore page when no keyword is specified and default sorting is used. + A repo is considered irrelevant if it's a fork or if it has no metadata (no description, no icon, no topic). ### UI - Admin (`ui.admin`) diff --git a/routers/web/explore/repo.go b/routers/web/explore/repo.go index cc3af8cb2c11..be5ad1b015b7 100644 --- a/routers/web/explore/repo.go +++ b/routers/web/explore/repo.go @@ -4,6 +4,7 @@ package explore import ( + "fmt" "net/http" "code.gitea.io/gitea/models/db" @@ -18,7 +19,7 @@ import ( const ( // tplExploreRepos explore repositories page template tplExploreRepos base.TplName = "explore/repos" - relevantReposOnlyParam string = "no_filter" + relevantReposOnlyParam string = "only_show_relevant" ) // RepoSearchOptions when calling search repositories @@ -137,7 +138,7 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) { pager.SetDefaultParams(ctx) pager.AddParam(ctx, "topic", "TopicOnly") pager.AddParam(ctx, "language", "Language") - pager.AddParamString(relevantReposOnlyParam, ctx.FormString(relevantReposOnlyParam)) + pager.AddParamString(relevantReposOnlyParam, fmt.Sprint(opts.OnlyShowRelevant)) ctx.Data["Page"] = pager ctx.HTML(http.StatusOK, opts.TplName) @@ -156,11 +157,18 @@ func Repos(ctx *context.Context) { ownerID = ctx.Doer.ID } + onlyShowRelevant := setting.UI.OnlyShowRelevantRepos + + _ = ctx.Req.ParseForm() // parse the form first, to prepare the ctx.Req.Form field + if len(ctx.Req.Form[relevantReposOnlyParam]) != 0 { + onlyShowRelevant = ctx.FormBool(relevantReposOnlyParam) + } + RenderRepoSearch(ctx, &RepoSearchOptions{ PageSize: setting.UI.ExplorePagingNum, OwnerID: ownerID, Private: ctx.Doer != nil, TplName: tplExploreRepos, - OnlyShowRelevant: !ctx.FormBool(relevantReposOnlyParam), + OnlyShowRelevant: onlyShowRelevant, }) } diff --git a/templates/explore/repo_search.tmpl b/templates/explore/repo_search.tmpl index 59d63b19d443..85c1be8e6e56 100644 --- a/templates/explore/repo_search.tmpl +++ b/templates/explore/repo_search.tmpl @@ -26,12 +26,15 @@
+ {{if .PageIsExploreRepositories}} + + {{end}}
-{{if .OnlyShowRelevant}} +{{if and .PageIsExploreRepositories .OnlyShowRelevant}}
- {{.locale.Tr "explore.relevant_repositories" ((printf "%s%s" $.Link "?no_filter=1")|Escape) | Safe}} + {{.locale.Tr "explore.relevant_repositories" ((printf "%s%s" $.Link "?only_show_relevant=0")|Escape) | Safe}}
{{end}}