mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-10-15 19:42:04 +00:00
feat: allow any README for .profile
(#8798)
closes #1624 Co-authored-by: Maxim Slipenko <maks1ms@altlinux.org> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8798 Reviewed-by: Otto <otto@codeberg.org> Co-authored-by: Maxim Slipenko <maks1ms@noreply.codeberg.org> Co-committed-by: Maxim Slipenko <maks1ms@noreply.codeberg.org>
This commit is contained in:
parent
a87153b089
commit
ed3b70cbb9
7 changed files with 102 additions and 34 deletions
|
@ -8,6 +8,8 @@ package user
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
gotemplate "html/template"
|
||||
"io"
|
||||
"net/http"
|
||||
"path"
|
||||
"strings"
|
||||
|
@ -269,23 +271,33 @@ func prepareUserProfileTabData(ctx *context.Context, showPrivate bool, profileDb
|
|||
} else {
|
||||
defer rc.Close()
|
||||
|
||||
if profileContent, err := markdown.RenderReader(&markup.RenderContext{
|
||||
Ctx: ctx,
|
||||
GitRepo: profileGitRepo,
|
||||
Links: markup.Links{
|
||||
// Give the repo link 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
|
||||
Base: profileDbRepo.Link(),
|
||||
BranchPath: path.Join("branch", util.PathEscapeSegments(profileDbRepo.DefaultBranch)),
|
||||
},
|
||||
Metas: map[string]string{"mode": "document"},
|
||||
}, rc); err != nil {
|
||||
log.Error("failed to RenderString: %v", err)
|
||||
if markupType := markup.Type(profileReadme.Name()); markupType != "" {
|
||||
if profileContent, err := markdown.RenderReader(&markup.RenderContext{
|
||||
Ctx: ctx,
|
||||
Type: markupType,
|
||||
GitRepo: profileGitRepo,
|
||||
Links: markup.Links{
|
||||
// Give the repo link 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
|
||||
Base: profileDbRepo.Link(),
|
||||
BranchPath: path.Join("branch", util.PathEscapeSegments(profileDbRepo.DefaultBranch)),
|
||||
},
|
||||
Metas: map[string]string{"mode": "document"},
|
||||
}, rc); err != nil {
|
||||
log.Error("failed to RenderString: %v", err)
|
||||
} else {
|
||||
ctx.Data["ProfileReadme"] = profileContent
|
||||
}
|
||||
} else {
|
||||
ctx.Data["ProfileReadme"] = profileContent
|
||||
content, err := io.ReadAll(rc)
|
||||
if err != nil {
|
||||
log.Error("Read readme content failed: %v", err)
|
||||
}
|
||||
ctx.Data["ProfileReadme"] = gotemplate.HTMLEscapeString(util.UnsafeBytesToString(content))
|
||||
ctx.Data["IsProfileReadmePlain"] = true
|
||||
}
|
||||
}
|
||||
default: // default to "repositories"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue