Skip to content

Commit ae65cba

Browse files
GustedGusted
authored and
Otto Richter
committed
CB/feat: Only show relevant repositories on explore page (!32)
- Add go-gitea#19361 - Remove the HideMirror codeberg-specific option(not needed anymore with this patch). - Only show relevant repositories by default(no keyword given and not disabled). - Backporting this feature to test it's impact, and solve Codeberg/Community#575 Co-authored-by: Gusted <[email protected]> Reviewed-on: https://codeberg.org/Codeberg/gitea/pulls/32 Co-authored-by: Gusted <[email protected]> Co-committed-by: Gusted <[email protected]>
1 parent 0d4752c commit ae65cba

File tree

6 files changed

+50
-18
lines changed

6 files changed

+50
-18
lines changed

Diff for: models/repo_list.go

+23-2
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ type SearchRepoOptions struct {
144144
HasMilestones util.OptionalBool
145145
// LowerNames represents valid lower names to restrict to
146146
LowerNames []string
147+
// When specified true, apply some filters over the conditions:
148+
// - Don't show forks, when opts.Fork is OptionalBoolNone.
149+
// - Do not display repositories that lacks a description, icon and topic.
150+
OnlyShowRelevant bool
147151
}
148152

149153
// SearchOrderBy is used to sort the result
@@ -439,8 +443,12 @@ func SearchRepositoryCondition(opts *SearchRepoOptions) builder.Cond {
439443
cond = cond.And(keywordCond)
440444
}
441445

442-
if opts.Fork != util.OptionalBoolNone {
443-
cond = cond.And(builder.Eq{"is_fork": opts.Fork == util.OptionalBoolTrue})
446+
if opts.Fork != util.OptionalBoolNone || opts.OnlyShowRelevant {
447+
if opts.OnlyShowRelevant && opts.Fork == util.OptionalBoolNone {
448+
cond = cond.And(builder.Eq{"is_fork": false})
449+
} else {
450+
cond = cond.And(builder.Eq{"is_fork": opts.Fork == util.OptionalBoolTrue})
451+
}
444452
}
445453

446454
if opts.Mirror != util.OptionalBoolNone {
@@ -462,6 +470,19 @@ func SearchRepositoryCondition(opts *SearchRepoOptions) builder.Cond {
462470
cond = cond.And(builder.Eq{"num_milestones": 0}.Or(builder.IsNull{"num_milestones"}))
463471
}
464472

473+
if opts.OnlyShowRelevant {
474+
// Only show a repo that either has a topic or description.
475+
subQueryCond := builder.NewCond()
476+
477+
// Topic checking. topics is non-null.
478+
subQueryCond = subQueryCond.Or(builder.Neq{"topics": "null"})
479+
480+
// Description checking. Description not empty.
481+
subQueryCond = subQueryCond.Or(builder.Neq{"description": ""})
482+
483+
cond = cond.And(subQueryCond)
484+
}
485+
465486
return cond
466487
}
467488

Diff for: modules/setting/setting.go

+2
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ var (
226226
CustomEmojisMap map[string]string `ini:"-"`
227227
SearchRepoDescription bool
228228
UseServiceWorker bool
229+
OnlyShowRelevantRepos bool
229230

230231
Notification struct {
231232
MinTimeout time.Duration
@@ -1025,6 +1026,7 @@ func loadFromConf(allowEmpty bool, extraConfig string) {
10251026
UI.DefaultShowFullName = Cfg.Section("ui").Key("DEFAULT_SHOW_FULL_NAME").MustBool(false)
10261027
UI.SearchRepoDescription = Cfg.Section("ui").Key("SEARCH_REPO_DESCRIPTION").MustBool(true)
10271028
UI.UseServiceWorker = Cfg.Section("ui").Key("USE_SERVICE_WORKER").MustBool(false)
1029+
UI.OnlyShowRelevantRepos = Cfg.Section("ui").Key("ONLY_SHOW_RELEVANT_REPOS").MustBool(false)
10281030

10291031
HasRobotsTxt, err = util.IsFile(path.Join(CustomPath, "robots.txt"))
10301032
if err != nil {

Diff for: options/locale/locale_en-US.ini

+2
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,8 @@ org_no_results = No matching organizations found.
274274
code_no_results = No source code matching your search term found.
275275
code_search_results = Search results for '%s'
276276
code_last_indexed_at = Last indexed %s
277+
relevant_repositories_tooltip = Repositories that are forks or don't have a topic and description aren't being shown.
278+
relevant_repositories = Only relevant repositories are being shown, <a href="%s">show unfiltered results</a>.
277279

278280
[auth]
279281
create_new_account = Register Account

Diff for: routers/web/explore/repo.go

+12-16
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ type RepoSearchOptions struct {
2828
Restricted bool
2929
PageSize int
3030
TplName base.TplName
31-
// codeberg: Hide mirrors from explore view
32-
HideMirror util.OptionalBool
3331
}
3432

3533
// RenderRepoSearch render repositories search page
@@ -40,10 +38,11 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
4038
}
4139

4240
var (
43-
repos []*repo_model.Repository
44-
count int64
45-
err error
46-
orderBy db.SearchOrderBy
41+
repos []*repo_model.Repository
42+
count int64
43+
err error
44+
orderBy db.SearchOrderBy
45+
onlyShowRelevant bool
4746
)
4847

4948
ctx.Data["SortType"] = ctx.FormString("sort")
@@ -75,18 +74,18 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
7574
default:
7675
ctx.Data["SortType"] = "recentupdate"
7776
orderBy = db.SearchOrderByRecentUpdated
77+
onlyShowRelevant = setting.UI.OnlyShowRelevantRepos && !ctx.FormBool("no_filter")
7878
}
7979

8080
keyword := ctx.FormTrim("q")
81+
if keyword != "" {
82+
onlyShowRelevant = false
83+
}
84+
85+
ctx.Data["OnlyShowRelevant"] = onlyShowRelevant
8186
topicOnly := ctx.FormBool("topic")
8287
ctx.Data["TopicOnly"] = topicOnly
8388

84-
// codeberg: Hide mirrors from explore view
85-
var showMirror util.OptionalBool = util.OptionalBoolNone
86-
if (opts.HideMirror == util.OptionalBoolTrue) && (keyword == "") {
87-
showMirror = util.OptionalBoolFalse
88-
}
89-
9089
repos, count, err = models.SearchRepository(&models.SearchRepoOptions{
9190
ListOptions: db.ListOptions{
9291
Page: page,
@@ -101,8 +100,7 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
101100
AllLimited: true,
102101
TopicOnly: topicOnly,
103102
IncludeDescription: setting.UI.SearchRepoDescription,
104-
// codeberg: Hide mirrors from explore view
105-
Mirror: showMirror,
103+
OnlyShowRelevant: onlyShowRelevant,
106104
})
107105
if err != nil {
108106
ctx.ServerError("SearchRepository", err)
@@ -139,7 +137,5 @@ func Repos(ctx *context.Context) {
139137
OwnerID: ownerID,
140138
Private: ctx.User != nil,
141139
TplName: tplExploreRepos,
142-
// codeberg: Hide mirrors from explore view
143-
HideMirror: util.OptionalBoolTrue,
144140
})
145141
}

Diff for: templates/explore/repo_search.tmpl

+5
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,9 @@
2929
<button class="ui blue button">{{.i18n.Tr "explore.search"}}</button>
3030
</div>
3131
</form>
32+
{{if .OnlyShowRelevant}}
33+
<div class="ui blue attached message explore-relevancy-note">
34+
<span class="ui tooltip" data-content="{{.i18n.Tr "explore.relevant_repositories_tooltip"}}">{{.i18n.Tr "explore.relevant_repositories" ((printf "%s%s" $.Link "?no_filter=1")|Escape) | Safe}}</span>
35+
</div>
36+
{{end}}
3237
<div class="ui divider"></div>

Diff for: web_src/less/_explore.less

+6
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,9 @@
8989
}
9090
}
9191
}
92+
93+
.ui.explore-relevancy-note {
94+
border-top: 0;
95+
margin-top: 0;
96+
max-width: 90%;
97+
}

0 commit comments

Comments
 (0)