mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	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```  Example of user without ```.profile/README.md```  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>
This commit is contained in:
		@@ -16,6 +16,7 @@ import (
 | 
			
		||||
	repo_model "code.gitea.io/gitea/models/repo"
 | 
			
		||||
	user_model "code.gitea.io/gitea/models/user"
 | 
			
		||||
	"code.gitea.io/gitea/modules/context"
 | 
			
		||||
	"code.gitea.io/gitea/modules/git"
 | 
			
		||||
	"code.gitea.io/gitea/modules/markup"
 | 
			
		||||
	"code.gitea.io/gitea/modules/markup/markdown"
 | 
			
		||||
	"code.gitea.io/gitea/modules/setting"
 | 
			
		||||
@@ -91,6 +92,38 @@ func Profile(ctx *context.Context) {
 | 
			
		||||
		ctx.Data["RenderedDescription"] = content
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	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 {
 | 
			
		||||
			bytes, err := blob.GetBlobContent()
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				ctx.ServerError("GetBlobContent", err)
 | 
			
		||||
				return
 | 
			
		||||
			}
 | 
			
		||||
			profileContent, err := markdown.RenderString(&markup.RenderContext{
 | 
			
		||||
				Ctx:     ctx,
 | 
			
		||||
				GitRepo: gitRepo,
 | 
			
		||||
			}, bytes)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				ctx.ServerError("RenderString", err)
 | 
			
		||||
				return
 | 
			
		||||
			}
 | 
			
		||||
			ctx.Data["ProfileReadme"] = profileContent
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	showPrivate := ctx.IsSigned && (ctx.Doer.IsAdmin || ctx.Doer.ID == ctx.ContextUser.ID)
 | 
			
		||||
 | 
			
		||||
	orgs, err := organization.FindOrgs(organization.FindOrgOptions{
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user