Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Dec 27, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions routers/web/user/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package user
import (
"fmt"
"net/http"
"path"
"strings"

activities_model "code.gitea.io/gitea/models/activities"
Expand Down Expand Up @@ -233,10 +234,20 @@ func prepareUserProfileTabData(ctx *context.Context, showPrivate bool, profileGi
if bytes, err := profileReadme.GetBlobContent(setting.UI.MaxDisplayFileSize); err != nil {
log.Error("failed to GetBlobContent: %v", err)
} else {
// When user opens someone's profile page, the router doesn't give the repo context, which makes it difficult to
// render the full link of media elements.
// the media link should be in the format of /[user]/[repoName]/src/branch/[branchName],
// Eg. /Tom/.profile/src/branch/main
// The branch shown on the profile page should be the 'main' branch, this need to be in sync with doc, see:
// https://docs.gitea.com/usage/profile-readme
const profileBranch = "main"
katsusan marked this conversation as resolved.
Show resolved Hide resolved
repoName := strings.TrimSuffix(path.Base(profileGitRepo.Path), ".git")
katsusan marked this conversation as resolved.
Show resolved Hide resolved
prefix := fmt.Sprintf("/%s/%s/src/branch/%s", ctx.ContextUser.Name, repoName, profileBranch)
katsusan marked this conversation as resolved.
Show resolved Hide resolved
if profileContent, err := markdown.RenderString(&markup.RenderContext{
Ctx: ctx,
GitRepo: profileGitRepo,
Metas: map[string]string{"mode": "document"},
Ctx: ctx,
GitRepo: profileGitRepo,
URLPrefix: prefix,
Metas: map[string]string{"mode": "document"},
}, bytes); err != nil {
log.Error("failed to RenderString: %v", err)
} else {
Expand Down