aboutsummaryrefslogtreecommitdiffstats
path: root/routers/web/shared
diff options
context:
space:
mode:
authorNicholas Pease <34464552+LAX18@users.noreply.github.com>2023-05-09 01:57:24 -0400
committerGitHub <noreply@github.com>2023-05-09 05:57:24 +0000
commitc090f87a8db5b51e0aa9c7278b38ddc862c048ac (patch)
treeb3c81f50f1392dcfcaebe2ae0ea09dd3e74ac384 /routers/web/shared
parentb6fc2cdf82acc9792a3607dc4afba93f03fff9d7 (diff)
downloadgitea-c090f87a8db5b51e0aa9c7278b38ddc862c048ac.tar.gz
gitea-c090f87a8db5b51e0aa9c7278b38ddc862c048ac.zip
Add Gitea Profile Readmes (#23260)
Implements displaying a README.md file present in a users ```.profile``` repository on the users profile page. If no such repository/file is present, the user's profile page remains unchanged. Example of user with ```.profile/README.md``` ![image](https://user-images.githubusercontent.com/34464552/222757202-5d53ac62-60d9-432f-b9e3-2537ffa91041.png) Example of user without ```.profile/README.md``` ![image](https://user-images.githubusercontent.com/34464552/222759972-576e058b-acd4-47ac-be33-38a7cb58cc81.png) This pull request closes the feature request in #12233 Special thanks to @techknowlogick for the help in the Gitea discord! --------- Co-authored-by: techknowlogick <techknowlogick@gitea.io> Co-authored-by: Yarden Shoham <hrsi88@gmail.com> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: yp05327 <576951401@qq.com> Co-authored-by: Yarden Shoham <git@yardenshoham.com>
Diffstat (limited to 'routers/web/shared')
-rw-r--r--routers/web/shared/user/header.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/routers/web/shared/user/header.go b/routers/web/shared/user/header.go
index 05e45f999e..9594e6975a 100644
--- a/routers/web/shared/user/header.go
+++ b/routers/web/shared/user/header.go
@@ -4,7 +4,9 @@
package user
import (
+ repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/modules/context"
+ "code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/setting"
)
@@ -13,4 +15,24 @@ func RenderUserHeader(ctx *context.Context) {
ctx.Data["IsPackageEnabled"] = setting.Packages.Enabled
ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled
ctx.Data["ContextUser"] = ctx.ContextUser
+ tab := ctx.FormString("tab")
+ ctx.Data["TabName"] = tab
+ repo, err := repo_model.GetRepositoryByName(ctx.ContextUser.ID, ".profile")
+ if err == nil && !repo.IsEmpty {
+ gitRepo, err := git.OpenRepository(ctx, repo.RepoPath())
+ if err != nil {
+ ctx.ServerError("OpenRepository", err)
+ return
+ }
+ defer gitRepo.Close()
+ commit, err := gitRepo.GetBranchCommit(repo.DefaultBranch)
+ if err != nil {
+ ctx.ServerError("GetBranchCommit", err)
+ return
+ }
+ blob, err := commit.GetBlobByPath("README.md")
+ if err == nil && blob != nil {
+ ctx.Data["ProfileReadme"] = true
+ }
+ }
}