loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix wrong link in user and organization profile when using relative url (#28617)

fix #28436.
the doc https://docs.gitea.com/usage/profile-readme maybe also need to
be updated to tell that
the main branch is necessary,which means the following three conditions
should be satisfied:
- repo: **.profile**
- branch: **[default branch]**
- markdown: **README.md**

authored by

katsu and committed by
GitHub
42149ff1 baf0d402

+28 -15
+11 -6
routers/web/org/home.go
··· 18 18 "code.gitea.io/gitea/modules/markup" 19 19 "code.gitea.io/gitea/modules/markup/markdown" 20 20 "code.gitea.io/gitea/modules/setting" 21 + "code.gitea.io/gitea/modules/util" 21 22 shared_user "code.gitea.io/gitea/routers/web/shared/user" 22 23 ) 23 24 ··· 157 158 158 159 ctx.Data["ShowMemberAndTeamTab"] = ctx.Org.IsMember || len(members) > 0 159 160 160 - profileGitRepo, profileReadmeBlob, profileClose := shared_user.FindUserProfileReadme(ctx, ctx.Doer) 161 + profileDbRepo, profileGitRepo, profileReadmeBlob, profileClose := shared_user.FindUserProfileReadme(ctx, ctx.Doer) 161 162 defer profileClose() 162 - prepareOrgProfileReadme(ctx, profileGitRepo, profileReadmeBlob) 163 + prepareOrgProfileReadme(ctx, profileGitRepo, profileDbRepo, profileReadmeBlob) 163 164 164 165 ctx.HTML(http.StatusOK, tplOrgHome) 165 166 } 166 167 167 - func prepareOrgProfileReadme(ctx *context.Context, profileGitRepo *git.Repository, profileReadme *git.Blob) { 168 + func prepareOrgProfileReadme(ctx *context.Context, profileGitRepo *git.Repository, profileDbRepo *repo_model.Repository, profileReadme *git.Blob) { 168 169 if profileGitRepo == nil || profileReadme == nil { 169 170 return 170 171 } ··· 172 173 if bytes, err := profileReadme.GetBlobContent(setting.UI.MaxDisplayFileSize); err != nil { 173 174 log.Error("failed to GetBlobContent: %v", err) 174 175 } else { 176 + // Pass URLPrefix to markdown render for the full link of media elements. 177 + // The profile of default branch would be shown. 178 + prefix := profileDbRepo.Link() + "/src/branch/" + util.PathEscapeSegments(profileDbRepo.DefaultBranch) 175 179 if profileContent, err := markdown.RenderString(&markup.RenderContext{ 176 - Ctx: ctx, 177 - GitRepo: profileGitRepo, 178 - Metas: map[string]string{"mode": "document"}, 180 + Ctx: ctx, 181 + GitRepo: profileGitRepo, 182 + URLPrefix: prefix, 183 + Metas: map[string]string{"mode": "document"}, 179 184 }, bytes); err != nil { 180 185 log.Error("failed to RenderString: %v", err) 181 186 } else {
+3 -3
routers/web/shared/user/header.go
··· 87 87 } 88 88 } 89 89 90 - func FindUserProfileReadme(ctx *context.Context, doer *user_model.User) (profileGitRepo *git.Repository, profileReadmeBlob *git.Blob, profileClose func()) { 90 + func FindUserProfileReadme(ctx *context.Context, doer *user_model.User) (profileDbRepo *repo_model.Repository, profileGitRepo *git.Repository, profileReadmeBlob *git.Blob, profileClose func()) { 91 91 profileDbRepo, err := repo_model.GetRepositoryByName(ctx, ctx.ContextUser.ID, ".profile") 92 92 if err == nil { 93 93 perm, err := access_model.GetUserRepoPermission(ctx, profileDbRepo, doer) ··· 105 105 } else if !repo_model.IsErrRepoNotExist(err) { 106 106 log.Error("FindUserProfileReadme failed to GetRepositoryByName: %v", err) 107 107 } 108 - return profileGitRepo, profileReadmeBlob, func() { 108 + return profileDbRepo, profileGitRepo, profileReadmeBlob, func() { 109 109 if profileGitRepo != nil { 110 110 _ = profileGitRepo.Close() 111 111 } ··· 115 115 func RenderUserHeader(ctx *context.Context) { 116 116 prepareContextForCommonProfile(ctx) 117 117 118 - _, profileReadmeBlob, profileClose := FindUserProfileReadme(ctx, ctx.Doer) 118 + _, _, profileReadmeBlob, profileClose := FindUserProfileReadme(ctx, ctx.Doer) 119 119 defer profileClose() 120 120 ctx.Data["HasProfileReadme"] = profileReadmeBlob != nil 121 121 }
+14 -6
routers/web/user/profile.go
··· 64 64 ctx.Data["HeatmapTotalContributions"] = activities_model.GetTotalContributionsInHeatmap(data) 65 65 } 66 66 67 - profileGitRepo, profileReadmeBlob, profileClose := shared_user.FindUserProfileReadme(ctx, ctx.Doer) 67 + profileDbRepo, profileGitRepo, profileReadmeBlob, profileClose := shared_user.FindUserProfileReadme(ctx, ctx.Doer) 68 68 defer profileClose() 69 69 70 70 showPrivate := ctx.IsSigned && (ctx.Doer.IsAdmin || ctx.Doer.ID == ctx.ContextUser.ID) 71 - prepareUserProfileTabData(ctx, showPrivate, profileGitRepo, profileReadmeBlob) 71 + prepareUserProfileTabData(ctx, showPrivate, profileDbRepo, profileGitRepo, profileReadmeBlob) 72 72 // call PrepareContextForProfileBigAvatar later to avoid re-querying the NumFollowers & NumFollowing 73 73 shared_user.PrepareContextForProfileBigAvatar(ctx) 74 74 ctx.HTML(http.StatusOK, tplProfile) 75 75 } 76 76 77 - func prepareUserProfileTabData(ctx *context.Context, showPrivate bool, profileGitRepo *git.Repository, profileReadme *git.Blob) { 77 + func prepareUserProfileTabData(ctx *context.Context, showPrivate bool, profileDbRepo *repo_model.Repository, profileGitRepo *git.Repository, profileReadme *git.Blob) { 78 78 // if there is a profile readme, default to "overview" page, otherwise, default to "repositories" page 79 79 // if there is not a profile readme, the overview tab should be treated as the repositories tab 80 80 tab := ctx.FormString("tab") ··· 233 233 if bytes, err := profileReadme.GetBlobContent(setting.UI.MaxDisplayFileSize); err != nil { 234 234 log.Error("failed to GetBlobContent: %v", err) 235 235 } else { 236 + // Give the URLPrefix to the markdown render for the full link of media element. 237 + // the media link usually be like /[user]/[repoName]/media/branch/[branchName], 238 + // Eg. /Tom/.profile/media/branch/main 239 + // The branch shown on the profile page is the default branch, this need to be in sync with doc, see: 240 + // https://docs.gitea.com/usage/profile-readme 241 + 242 + prefix := profileDbRepo.Link() + "/src/branch/" + util.PathEscapeSegments(profileDbRepo.DefaultBranch) 236 243 if profileContent, err := markdown.RenderString(&markup.RenderContext{ 237 - Ctx: ctx, 238 - GitRepo: profileGitRepo, 239 - Metas: map[string]string{"mode": "document"}, 244 + Ctx: ctx, 245 + GitRepo: profileGitRepo, 246 + URLPrefix: prefix, 247 + Metas: map[string]string{"mode": "document"}, 240 248 }, bytes); err != nil { 241 249 log.Error("failed to RenderString: %v", err) 242 250 } else {