forked from gitea/gitea
		
	 c090f87a8d
			
		
	
	
		c090f87a8d
		
			
		
	
	
	
	
		
			
			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>
		
			
				
	
	
		
			39 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			39 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| // Copyright 2022 The Gitea Authors. All rights reserved.
 | |
| // SPDX-License-Identifier: MIT
 | |
| 
 | |
| 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"
 | |
| )
 | |
| 
 | |
| func RenderUserHeader(ctx *context.Context) {
 | |
| 	ctx.Data["IsProjectEnabled"] = true
 | |
| 	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
 | |
| 		}
 | |
| 	}
 | |
| }
 |