Skip to content

Commit 3864ed8

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: Remove `title` from elements on Org mode (go-gitea#27968) Add Profile Readme for Organisations (go-gitea#27955) Allow to set explore page default sort (go-gitea#27951)
2 parents fb42d31 + 481e738 commit 3864ed8

File tree

13 files changed

+74
-27
lines changed

13 files changed

+74
-27
lines changed

custom/conf/app.example.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,10 @@ LEVEL = Info
12381238
;; Whether to only show relevant repos on the explore page when no keyword is specified and default sorting is used.
12391239
;; A repo is considered irrelevant if it's a fork or if it has no metadata (no description, no icon, no topic).
12401240
;ONLY_SHOW_RELEVANT_REPOS = false
1241+
;;
1242+
;; Change the sort type of the explore pages.
1243+
;; Default is "recentupdate", but you also have "alphabetically", "reverselastlogin", "newest", "oldest".
1244+
;EXPLORE_PAGING_DEFAULT_SORT = recentupdate
12411245

12421246
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12431247
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,9 @@ The following configuration set `Content-Type: application/vnd.android.package-a
229229
add it to this config.
230230
- `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.
231231
- `SEARCH_REPO_DESCRIPTION`: **true**: Whether to search within description at repository search on explore page.
232-
- `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.
232+
- `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.
233233
A repo is considered irrelevant if it's a fork or if it has no metadata (no description, no icon, no topic).
234+
- `EXPLORE_PAGING_DEFAULT_SORT`: **recentupdate**: Change the sort type of the explore pages. Valid values are "recentupdate", "alphabetically", "reverselastlogin", "newest" and "oldest"
234235

235236
### UI - Admin (`ui.admin`)
236237

docs/content/usage/profile-readme.en-us.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ menu:
1515

1616
# Profile READMEs
1717

18-
To display a Markdown file in your Gitea profile page, simply create a repository named `.profile` and add a new file called `README.md`. Gitea will automatically display the contents of the file on your profile, above your repositories.
18+
To display a Markdown file in your Gitea user or organization profile page, create a repository named `.profile` and add a new file named `README.md` to it.
19+
Gitea will automatically display the contents of the file on your profile, in a new "Overview" above your repositories.
1920

2021
Making the `.profile` repository private will hide the Profile README.

modules/markup/orgmode/orgmode.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func (r *Writer) WriteRegularLink(l org.RegularLink) {
158158
case "image":
159159
if l.Description == nil {
160160
imageSrc := getMediaURL(link)
161-
fmt.Fprintf(r, `<img src="%s" alt="%s" title="%s" />`, imageSrc, link, link)
161+
fmt.Fprintf(r, `<img src="%s" alt="%s" />`, imageSrc, link)
162162
} else {
163163
description := strings.TrimPrefix(org.String(l.Description...), "file:")
164164
imageSrc := getMediaURL([]byte(description))
@@ -167,18 +167,18 @@ func (r *Writer) WriteRegularLink(l org.RegularLink) {
167167
case "video":
168168
if l.Description == nil {
169169
imageSrc := getMediaURL(link)
170-
fmt.Fprintf(r, `<video src="%s" title="%s">%s</video>`, imageSrc, link, link)
170+
fmt.Fprintf(r, `<video src="%s">%s</video>`, imageSrc, link)
171171
} else {
172172
description := strings.TrimPrefix(org.String(l.Description...), "file:")
173173
videoSrc := getMediaURL([]byte(description))
174-
fmt.Fprintf(r, `<a href="%s"><video src="%s" title="%s"></video></a>`, link, videoSrc, videoSrc)
174+
fmt.Fprintf(r, `<a href="%s"><video src="%s">%s</video></a>`, link, videoSrc, videoSrc)
175175
}
176176
default:
177177
description := string(link)
178178
if l.Description != nil {
179179
description = r.WriteNodesAsString(l.Description...)
180180
}
181-
fmt.Fprintf(r, `<a href="%s" title="%s">%s</a>`, link, description, description)
181+
fmt.Fprintf(r, `<a href="%s">%s</a>`, link, description)
182182
}
183183
}
184184

modules/markup/orgmode/orgmode_test.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ func TestRender_StandardLinks(t *testing.T) {
3434
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer))
3535
}
3636

37-
googleRendered := "<p><a href=\"https://google.com/\" title=\"https://google.com/\">https://google.com/</a></p>"
38-
test("[[https://google.com/]]", googleRendered)
37+
test("[[https://google.com/]]",
38+
`<p><a href="https://google.com/">https://google.com/</a></p>`)
3939

4040
lnk := util.URLJoin(AppSubURL, "WikiPage")
4141
test("[[WikiPage][WikiPage]]",
42-
"<p><a href=\""+lnk+"\" title=\"WikiPage\">WikiPage</a></p>")
42+
`<p><a href="`+lnk+`">WikiPage</a></p>`)
4343
}
4444

4545
func TestRender_Media(t *testing.T) {
@@ -59,19 +59,23 @@ func TestRender_Media(t *testing.T) {
5959
result := util.URLJoin(AppSubURL, url)
6060

6161
test("[[file:"+url+"]]",
62-
"<p><img src=\""+result+"\" alt=\""+result+"\" title=\""+result+"\" /></p>")
62+
`<p><img src="`+result+`" alt="`+result+`" /></p>`)
6363

6464
// With description.
6565
test("[[https://example.com][https://example.com/example.svg]]",
6666
`<p><a href="https://example.com"><img src="https://example.com/example.svg" alt="https://example.com/example.svg" /></a></p>`)
67+
test("[[https://example.com][pre https://example.com/example.svg post]]",
68+
`<p><a href="https://example.com">pre <img src="https://example.com/example.svg" alt="https://example.com/example.svg" /> post</a></p>`)
6769
test("[[https://example.com][https://example.com/example.mp4]]",
68-
`<p><a href="https://example.com"><video src="https://example.com/example.mp4" title="https://example.com/example.mp4"></video></a></p>`)
70+
`<p><a href="https://example.com"><video src="https://example.com/example.mp4">https://example.com/example.mp4</video></a></p>`)
71+
test("[[https://example.com][pre https://example.com/example.mp4 post]]",
72+
`<p><a href="https://example.com">pre <video src="https://example.com/example.mp4">https://example.com/example.mp4</video> post</a></p>`)
6973

7074
// Without description.
7175
test("[[https://example.com/example.svg]]",
72-
`<p><img src="https://example.com/example.svg" alt="https://example.com/example.svg" title="https://example.com/example.svg" /></p>`)
76+
`<p><img src="https://example.com/example.svg" alt="https://example.com/example.svg" /></p>`)
7377
test("[[https://example.com/example.mp4]]",
74-
`<p><video src="https://example.com/example.mp4" title="https://example.com/example.mp4">https://example.com/example.mp4</video></p>`)
78+
`<p><video src="https://example.com/example.mp4">https://example.com/example.mp4</video></p>`)
7579
}
7680

7781
func TestRender_Source(t *testing.T) {

modules/setting/ui.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ var UI = struct {
3333
CustomEmojisMap map[string]string `ini:"-"`
3434
SearchRepoDescription bool
3535
OnlyShowRelevantRepos bool
36+
ExploreDefaultSort string `ini:"EXPLORE_PAGING_DEFAULT_SORT"`
3637

3738
Notification struct {
3839
MinTimeout time.Duration

routers/web/admin/orgs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func Organizations(ctx *context.Context) {
2424
ctx.Data["PageIsAdminOrganizations"] = true
2525

2626
if ctx.FormString("sort") == "" {
27-
ctx.SetFormString("sort", explore.UserSearchDefaultAdminSort)
27+
ctx.SetFormString("sort", UserSearchDefaultAdminSort)
2828
}
2929

3030
explore.RenderUserSearch(ctx, &user_model.SearchUserOptions{

routers/web/admin/users.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ const (
3737
tplUserEdit base.TplName = "admin/user/edit"
3838
)
3939

40+
// UserSearchDefaultAdminSort is the default sort type for admin view
41+
const UserSearchDefaultAdminSort = "alphabetically"
42+
4043
// Users show all the users
4144
func Users(ctx *context.Context) {
4245
ctx.Data["Title"] = ctx.Tr("admin.users")
@@ -56,7 +59,7 @@ func Users(ctx *context.Context) {
5659

5760
sortType := ctx.FormString("sort")
5861
if sortType == "" {
59-
sortType = explore.UserSearchDefaultAdminSort
62+
sortType = UserSearchDefaultAdminSort
6063
ctx.SetFormString("sort", sortType)
6164
}
6265
ctx.PageData["adminUserListSearchForm"] = map[string]any{

routers/web/explore/org.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func Organizations(ctx *context.Context) {
2525
}
2626

2727
if ctx.FormString("sort") == "" {
28-
ctx.SetFormString("sort", UserSearchDefaultSortType)
28+
ctx.SetFormString("sort", setting.UI.ExploreDefaultSort)
2929
}
3030

3131
RenderUserSearch(ctx, &user_model.SearchUserOptions{

routers/web/explore/repo.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,13 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
5757
orderBy db.SearchOrderBy
5858
)
5959

60-
ctx.Data["SortType"] = ctx.FormString("sort")
61-
switch ctx.FormString("sort") {
60+
sortOrder := ctx.FormString("sort")
61+
if sortOrder == "" {
62+
sortOrder = setting.UI.ExploreDefaultSort
63+
}
64+
ctx.Data["SortType"] = sortOrder
65+
66+
switch sortOrder {
6267
case "newest":
6368
orderBy = db.SearchOrderByNewest
6469
case "oldest":

routers/web/explore/user.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ const (
2323
tplExploreUsers base.TplName = "explore/users"
2424
)
2525

26-
// UserSearchDefaultSortType is the default sort type for user search
27-
const (
28-
UserSearchDefaultSortType = "recentupdate"
29-
UserSearchDefaultAdminSort = "alphabetically"
30-
)
31-
3226
var nullByte = []byte{0x00}
3327

3428
func isKeywordValid(keyword string) bool {
@@ -60,8 +54,13 @@ func RenderUserSearch(ctx *context.Context, opts *user_model.SearchUserOptions,
6054

6155
// we can not set orderBy to `models.SearchOrderByXxx`, because there may be a JOIN in the statement, different tables may have the same name columns
6256

63-
ctx.Data["SortType"] = ctx.FormString("sort")
64-
switch ctx.FormString("sort") {
57+
sortOrder := ctx.FormString("sort")
58+
if sortOrder == "" {
59+
sortOrder = setting.UI.ExploreDefaultSort
60+
}
61+
ctx.Data["SortType"] = sortOrder
62+
63+
switch sortOrder {
6564
case "newest":
6665
orderBy = "`user`.id DESC"
6766
case "oldest":
@@ -134,7 +133,7 @@ func Users(ctx *context.Context) {
134133
ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled
135134

136135
if ctx.FormString("sort") == "" {
137-
ctx.SetFormString("sort", UserSearchDefaultSortType)
136+
ctx.SetFormString("sort", setting.UI.ExploreDefaultSort)
138137
}
139138

140139
RenderUserSearch(ctx, &user_model.SearchUserOptions{

routers/web/org/home.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import (
1313
user_model "code.gitea.io/gitea/models/user"
1414
"code.gitea.io/gitea/modules/base"
1515
"code.gitea.io/gitea/modules/context"
16+
"code.gitea.io/gitea/modules/git"
17+
"code.gitea.io/gitea/modules/log"
1618
"code.gitea.io/gitea/modules/markup"
1719
"code.gitea.io/gitea/modules/markup/markdown"
1820
"code.gitea.io/gitea/modules/setting"
@@ -155,5 +157,29 @@ func Home(ctx *context.Context) {
155157

156158
ctx.Data["ShowMemberAndTeamTab"] = ctx.Org.IsMember || len(members) > 0
157159

160+
profileGitRepo, profileReadmeBlob, profileClose := shared_user.FindUserProfileReadme(ctx)
161+
defer profileClose()
162+
prepareOrgProfileReadme(ctx, profileGitRepo, profileReadmeBlob)
163+
158164
ctx.HTML(http.StatusOK, tplOrgHome)
159165
}
166+
167+
func prepareOrgProfileReadme(ctx *context.Context, profileGitRepo *git.Repository, profileReadme *git.Blob) {
168+
if profileGitRepo == nil || profileReadme == nil {
169+
return
170+
}
171+
172+
if bytes, err := profileReadme.GetBlobContent(setting.UI.MaxDisplayFileSize); err != nil {
173+
log.Error("failed to GetBlobContent: %v", err)
174+
} else {
175+
if profileContent, err := markdown.RenderString(&markup.RenderContext{
176+
Ctx: ctx,
177+
GitRepo: profileGitRepo,
178+
Metas: map[string]string{"mode": "document"},
179+
}, bytes); err != nil {
180+
log.Error("failed to RenderString: %v", err)
181+
} else {
182+
ctx.Data["ProfileReadme"] = profileContent
183+
}
184+
}
185+
}

templates/org/home.tmpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
<div class="ui container">
3939
<div class="ui mobile reversed stackable grid">
4040
<div class="ui {{if .ShowMemberAndTeamTab}}eleven wide{{end}} column">
41+
{{if .ProfileReadme}}
42+
<div id="readme_profile" class="markup">{{.ProfileReadme | Str2html}}</div>
43+
{{end}}
4144
{{template "explore/repo_search" .}}
4245
{{template "explore/repo_list" .}}
4346
{{template "base/paginate" .}}

0 commit comments

Comments
 (0)