From 603573366a203efae06f818a0b220be964cdac21 Mon Sep 17 00:00:00 2001 From: 6543 Date: Thu, 9 Nov 2023 15:05:52 +0100 Subject: [PATCH] Add Profile Readme for Organisations (#27955) https://blog.gitea.com/release-of-1.20.0/#-user-profile-readme-23260 (#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 Co-authored-by: KN4CK3R --- docs/content/usage/profile-readme.en-us.md | 3 ++- routers/web/org/home.go | 26 ++++++++++++++++++++++ templates/org/home.tmpl | 3 +++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/docs/content/usage/profile-readme.en-us.md b/docs/content/usage/profile-readme.en-us.md index 045d33d1c1..339176f7d4 100644 --- a/docs/content/usage/profile-readme.en-us.md +++ b/docs/content/usage/profile-readme.en-us.md @@ -15,6 +15,7 @@ menu: # Profile READMEs -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. +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. +Gitea will automatically display the contents of the file on your profile, in a new "Overview" above your repositories. Making the `.profile` repository private will hide the Profile README. diff --git a/routers/web/org/home.go b/routers/web/org/home.go index ec866eb6b3..4a8ebb670a 100644 --- a/routers/web/org/home.go +++ b/routers/web/org/home.go @@ -13,6 +13,8 @@ import ( user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/git" + "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/markup" "code.gitea.io/gitea/modules/markup/markdown" "code.gitea.io/gitea/modules/setting" @@ -155,5 +157,29 @@ func Home(ctx *context.Context) { ctx.Data["ShowMemberAndTeamTab"] = ctx.Org.IsMember || len(members) > 0 + profileGitRepo, profileReadmeBlob, profileClose := shared_user.FindUserProfileReadme(ctx) + defer profileClose() + prepareOrgProfileReadme(ctx, profileGitRepo, profileReadmeBlob) + ctx.HTML(http.StatusOK, tplOrgHome) } + +func prepareOrgProfileReadme(ctx *context.Context, profileGitRepo *git.Repository, profileReadme *git.Blob) { + if profileGitRepo == nil || profileReadme == nil { + return + } + + if bytes, err := profileReadme.GetBlobContent(setting.UI.MaxDisplayFileSize); err != nil { + log.Error("failed to GetBlobContent: %v", err) + } else { + if profileContent, err := markdown.RenderString(&markup.RenderContext{ + Ctx: ctx, + GitRepo: profileGitRepo, + Metas: map[string]string{"mode": "document"}, + }, bytes); err != nil { + log.Error("failed to RenderString: %v", err) + } else { + ctx.Data["ProfileReadme"] = profileContent + } + } +} diff --git a/templates/org/home.tmpl b/templates/org/home.tmpl index ee3237d45b..2bebcc0f87 100644 --- a/templates/org/home.tmpl +++ b/templates/org/home.tmpl @@ -38,6 +38,9 @@
+ {{if .ProfileReadme}} +
{{.ProfileReadme | Str2html}}
+ {{end}} {{template "explore/repo_search" .}} {{template "explore/repo_list" .}} {{template "base/paginate" .}}