From 74652a6c814399e4dcfe72df3a4456401ff17892 Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Tue, 16 Jan 2024 13:38:07 +0000 Subject: [PATCH] Revert "[GITEA] Fix wrong link in user and organization profile when using relative url" This reverts commit 658475dd2195373742172440fdfe42861d42ba10. --- routers/web/shared/user/header.go | 6 +++--- routers/web/user/profile.go | 20 ++++++-------------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/routers/web/shared/user/header.go b/routers/web/shared/user/header.go index 1e937b57ce..bf90399826 100644 --- a/routers/web/shared/user/header.go +++ b/routers/web/shared/user/header.go @@ -85,7 +85,7 @@ func PrepareContextForProfileBigAvatar(ctx *context.Context) { } } -func FindUserProfileReadme(ctx *context.Context) (profileDbRepo *repo_model.Repository, profileGitRepo *git.Repository, profileReadmeBlob *git.Blob, profileClose func()) { +func FindUserProfileReadme(ctx *context.Context) (profileGitRepo *git.Repository, profileReadmeBlob *git.Blob, profileClose func()) { profileDbRepo, err := repo_model.GetRepositoryByName(ctx.ContextUser.ID, ".profile") if err == nil && !profileDbRepo.IsEmpty && !profileDbRepo.IsPrivate { if profileGitRepo, err = git.OpenRepository(ctx, profileDbRepo.RepoPath()); err != nil { @@ -98,7 +98,7 @@ func FindUserProfileReadme(ctx *context.Context) (profileDbRepo *repo_model.Repo } } } - return profileDbRepo, profileGitRepo, profileReadmeBlob, func() { + return profileGitRepo, profileReadmeBlob, func() { if profileGitRepo != nil { _ = profileGitRepo.Close() } @@ -108,7 +108,7 @@ func FindUserProfileReadme(ctx *context.Context) (profileDbRepo *repo_model.Repo func RenderUserHeader(ctx *context.Context) { prepareContextForCommonProfile(ctx) - _, _, profileReadmeBlob, profileClose := FindUserProfileReadme(ctx) + _, profileReadmeBlob, profileClose := FindUserProfileReadme(ctx) defer profileClose() ctx.Data["HasProfileReadme"] = profileReadmeBlob != nil } diff --git a/routers/web/user/profile.go b/routers/web/user/profile.go index be6ca45ab6..1166e2f2de 100644 --- a/routers/web/user/profile.go +++ b/routers/web/user/profile.go @@ -66,17 +66,17 @@ func userProfile(ctx *context.Context) { ctx.Data["HeatmapTotalContributions"] = activities_model.GetTotalContributionsInHeatmap(data) } - profileDbRepo, profileGitRepo, profileReadmeBlob, profileClose := shared_user.FindUserProfileReadme(ctx) + profileGitRepo, profileReadmeBlob, profileClose := shared_user.FindUserProfileReadme(ctx) defer profileClose() showPrivate := ctx.IsSigned && (ctx.Doer.IsAdmin || ctx.Doer.ID == ctx.ContextUser.ID) - prepareUserProfileTabData(ctx, showPrivate, profileDbRepo, profileGitRepo, profileReadmeBlob) + prepareUserProfileTabData(ctx, showPrivate, profileGitRepo, profileReadmeBlob) // call PrepareContextForProfileBigAvatar later to avoid re-querying the NumFollowers & NumFollowing shared_user.PrepareContextForProfileBigAvatar(ctx) ctx.HTML(http.StatusOK, tplProfile) } -func prepareUserProfileTabData(ctx *context.Context, showPrivate bool, profileDbRepo *repo_model.Repository, profileGitRepo *git.Repository, profileReadme *git.Blob) { +func prepareUserProfileTabData(ctx *context.Context, showPrivate bool, profileGitRepo *git.Repository, profileReadme *git.Blob) { // if there is a profile readme, default to "overview" page, otherwise, default to "repositories" page // if there is not a profile readme, the overview tab should be treated as the repositories tab tab := ctx.FormString("tab") @@ -235,18 +235,10 @@ func prepareUserProfileTabData(ctx *context.Context, showPrivate bool, profileDb if bytes, err := profileReadme.GetBlobContent(setting.UI.MaxDisplayFileSize); err != nil { log.Error("failed to GetBlobContent: %v", err) } else { - // Give the URLPrefix to the markdown render for the full link of media element. - // the media link usually be like /[user]/[repoName]/media/branch/[branchName], - // Eg. /Tom/.profile/media/branch/main - // The branch shown on the profile page is the default branch, this need to be in sync with doc, see: - // https://docs.gitea.com/usage/profile-readme - - prefix := profileDbRepo.Link() + "/src/branch/" + util.PathEscapeSegments(profileDbRepo.DefaultBranch) if profileContent, err := markdown.RenderString(&markup.RenderContext{ - Ctx: ctx, - GitRepo: profileGitRepo, - URLPrefix: prefix, - Metas: map[string]string{"mode": "document"}, + Ctx: ctx, + GitRepo: profileGitRepo, + Metas: map[string]string{"mode": "document"}, }, bytes); err != nil { log.Error("failed to RenderString: %v", err) } else {