Skip to content

Commit b4e8a15

Browse files
6543silverwindKN4CK3R
authored andcommitted
Add Profile Readme for Organisations (go-gitea#27955)
https://blog.gitea.com/release-of-1.20.0/#-user-profile-readme-23260 (go-gitea#23260) did introduce Profile Readme for Users. This makes it usable for Organisations: ![image](https://github.com/go-gitea/gitea/assets/24977596/464ab58b-a952-414b-8a34-6deaeb4f7d35) --- *Sponsored by Kithara Software GmbH* --------- Co-authored-by: silverwind <[email protected]> Co-authored-by: KN4CK3R <[email protected]>
1 parent f3ef271 commit b4e8a15

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

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.

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)