@@ -64,17 +64,17 @@ func userProfile(ctx *context.Context) {
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,10 +233,18 @@ func prepareUserProfileTabData(ctx *context.Context, showPrivate bool, profileGi
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 {
0 commit comments