Skip to content

Commit d15f20b

Browse files
authored
Add ONLY_SHOW_RELEVANT_REPOS back, fix explore page bug, make code more strict (go-gitea#23766) (go-gitea#23791)
Follow go-gitea#21962 After I eat my own dogfood, I would say that ONLY_SHOW_RELEVANT_REPOS=false is necessary for many private/enterprise instances, because many private repositories do not have "description/topic", users just want to search by their names. This PR also adds `PageIsExploreRepositories` check, to make code more strict, because the `search` template is shared for different purpose. And during the test, I found a bug that the "Search" button didn't respect the "relevant" parameter, so this PR fixes the bug by the way together.
1 parent 863da7d commit d15f20b

File tree

5 files changed

+26
-6
lines changed

5 files changed

+26
-6
lines changed

custom/conf/app.example.ini

+4
Original file line numberDiff line numberDiff line change
@@ -1226,6 +1226,10 @@ ROUTER = console
12261226
;;
12271227
;; Whether to enable a Service Worker to cache frontend assets
12281228
;USE_SERVICE_WORKER = false
1229+
;;
1230+
;; Whether to only show relevant repos on the explore page when no keyword is specified and default sorting is used.
1231+
;; A repo is considered irrelevant if it's a fork or if it has no metadata (no description, no icon, no topic).
1232+
;ONLY_SHOW_RELEVANT_REPOS = false
12291233

12301234
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12311235
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

docs/content/doc/administration/config-cheat-sheet.en-us.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,13 @@ The following configuration set `Content-Type: application/vnd.android.package-a
226226
Values can be emoji alias (:smile:) or a unicode emoji.
227227
For custom reactions, add a tightly cropped square image to public/img/emoji/reaction_name.png
228228
- `CUSTOM_EMOJIS`: **gitea, codeberg, gitlab, git, github, gogs**: Additional Emojis not defined in the utf8 standard.
229-
By default we support Gitea (:gitea:), to add more copy them to public/img/emoji/emoji_name.png and
229+
By default, we support Gitea (:gitea:), to add more copy them to public/img/emoji/emoji_name.png and
230230
add it to this config.
231231
- `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.
232232
- `SEARCH_REPO_DESCRIPTION`: **true**: Whether to search within description at repository search on explore page.
233233
- `USE_SERVICE_WORKER`: **false**: Whether to enable a Service Worker to cache frontend assets.
234+
- `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.
235+
A repo is considered irrelevant if it's a fork or if it has no metadata (no description, no icon, no topic).
234236

235237
### UI - Admin (`ui.admin`)
236238

modules/setting/ui.go

+3
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ func loadUIFrom(rootCfg ConfigProvider) {
139139
UI.DefaultShowFullName = sec.Key("DEFAULT_SHOW_FULL_NAME").MustBool(false)
140140
UI.SearchRepoDescription = sec.Key("SEARCH_REPO_DESCRIPTION").MustBool(true)
141141
UI.UseServiceWorker = sec.Key("USE_SERVICE_WORKER").MustBool(false)
142+
143+
// OnlyShowRelevantRepos=false is important for many private/enterprise instances,
144+
// because many private repositories do not have "description/topic", users just want to search by their names.
142145
UI.OnlyShowRelevantRepos = sec.Key("ONLY_SHOW_RELEVANT_REPOS").MustBool(false)
143146

144147
UI.ReactionsLookup = make(container.Set[string])

routers/web/explore/repo.go

+11-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package explore
55

66
import (
7+
"fmt"
78
"net/http"
89

910
"code.gitea.io/gitea/models/db"
@@ -18,7 +19,7 @@ import (
1819
const (
1920
// tplExploreRepos explore repositories page template
2021
tplExploreRepos base.TplName = "explore/repos"
21-
relevantReposOnlyParam string = "no_filter"
22+
relevantReposOnlyParam string = "only_show_relevant"
2223
)
2324

2425
// RepoSearchOptions when calling search repositories
@@ -137,7 +138,7 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
137138
pager.SetDefaultParams(ctx)
138139
pager.AddParam(ctx, "topic", "TopicOnly")
139140
pager.AddParam(ctx, "language", "Language")
140-
pager.AddParamString(relevantReposOnlyParam, ctx.FormString(relevantReposOnlyParam))
141+
pager.AddParamString(relevantReposOnlyParam, fmt.Sprint(opts.OnlyShowRelevant))
141142
ctx.Data["Page"] = pager
142143

143144
ctx.HTML(http.StatusOK, opts.TplName)
@@ -156,11 +157,18 @@ func Repos(ctx *context.Context) {
156157
ownerID = ctx.Doer.ID
157158
}
158159

160+
onlyShowRelevant := setting.UI.OnlyShowRelevantRepos
161+
162+
_ = ctx.Req.ParseForm() // parse the form first, to prepare the ctx.Req.Form field
163+
if len(ctx.Req.Form[relevantReposOnlyParam]) != 0 {
164+
onlyShowRelevant = ctx.FormBool(relevantReposOnlyParam)
165+
}
166+
159167
RenderRepoSearch(ctx, &RepoSearchOptions{
160168
PageSize: setting.UI.ExplorePagingNum,
161169
OwnerID: ownerID,
162170
Private: ctx.Doer != nil,
163171
TplName: tplExploreRepos,
164-
OnlyShowRelevant: !ctx.FormBool(relevantReposOnlyParam),
172+
OnlyShowRelevant: onlyShowRelevant,
165173
})
166174
}

templates/explore/repo_search.tmpl

+5-2
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,15 @@
2626
<input type="hidden" name="language" value="{{$.Language}}">
2727
<div class="ui fluid action input">
2828
<input name="q" value="{{.Keyword}}" placeholder="{{.locale.Tr "explore.search"}}…" autofocus>
29+
{{if .PageIsExploreRepositories}}
30+
<input type="hidden" name="only_show_relevant" value="{{.OnlyShowRelevant}}">
31+
{{end}}
2932
<button class="ui primary button">{{.locale.Tr "explore.search"}}</button>
3033
</div>
3134
</form>
32-
{{if .OnlyShowRelevant}}
35+
{{if and .PageIsExploreRepositories .OnlyShowRelevant}}
3336
<div class="ui message explore-relevancy-note">
34-
<span class="ui tooltip" data-content="{{.locale.Tr "explore.relevant_repositories_tooltip"}}">{{.locale.Tr "explore.relevant_repositories" ((printf "%s%s" $.Link "?no_filter=1")|Escape) | Safe}}</span>
37+
<span class="ui tooltip" data-content="{{.locale.Tr "explore.relevant_repositories_tooltip"}}">{{.locale.Tr "explore.relevant_repositories" ((printf "%s%s" $.Link "?only_show_relevant=0")|Escape) | Safe}}</span>
3538
</div>
3639
{{end}}
3740
<div class="ui divider"></div>

0 commit comments

Comments
 (0)