diff --git a/routers/web/user/profile.go b/routers/web/user/profile.go index 40fc44ed14..2ad333a6af 100644 --- a/routers/web/user/profile.go +++ b/routers/web/user/profile.go @@ -9,6 +9,7 @@ import ( "fmt" "net/http" "path" + "reflect" "strings" "code.gitea.io/gitea/models" @@ -158,18 +159,30 @@ func Profile(ctx *context.Context) { ctx.Data["HeatmapData"] = data } - if len(ctxUser.Description) != 0 { - content, err := markdown.RenderString(&markup.RenderContext{ - URLPrefix: ctx.Repo.RepoLink, - Metas: map[string]string{"mode": "document"}, - GitRepo: ctx.Repo.GitRepo, - Ctx: ctx, - }, ctxUser.Description) - if err != nil { - ctx.ServerError("RenderString", err) - return - } - ctx.Data["RenderedDescription"] = content + var renderErr error + + renderErr = getRenderedTextField(ctx, ctxUser, "Description") + if renderErr != nil { + ctx.ServerError("RenderString", renderErr) + return + } + + renderErr = getRenderedTextField(ctx, ctxUser, "Competences") + if renderErr != nil { + ctx.ServerError("RenderString", renderErr) + return + } + + renderErr = getRenderedTextField(ctx, ctxUser, "Resources") + if renderErr != nil { + ctx.ServerError("RenderString", renderErr) + return + } + + renderErr = getRenderedTextField(ctx, ctxUser, "Interests") + if renderErr != nil { + ctx.ServerError("RenderString", renderErr) + return } showPrivate := ctx.IsSigned && (ctx.User.IsAdmin || ctx.User.ID == ctxUser.ID) @@ -377,3 +390,28 @@ func Action(ctx *context.Context) { // FIXME: We should check this URL and make sure that it's a valid Gitea URL ctx.RedirectToFirst(ctx.FormString("redirect_to"), u.HomeLink()) } + +func getTextField(user *user_model.User, fieldName string) string { + reflectedObj := reflect.ValueOf(user) + dynamicField := reflect.Indirect(reflectedObj).FieldByName(fieldName) + return dynamicField.String() +} + +func getRenderedTextField(ctx *context.Context, ctxUser *user_model.User, fieldName string) error { + var err error = nil + var content string + fieldVal := getTextField(ctxUser, fieldName) + if len(fieldVal) != 0 { + content, err = markdown.RenderString(&markup.RenderContext{ + URLPrefix: ctx.Repo.RepoLink, + Metas: map[string]string{"mode": "document"}, + GitRepo: ctx.Repo.GitRepo, + Ctx: ctx, + }, fieldVal) + if err == nil { + renderedFieldName := fmt.Sprintf("Rendered%s", fieldName) + ctx.Data[renderedFieldName] = content + } + } + return err +} diff --git a/templates/user/profile.tmpl b/templates/user/profile.tmpl index d14a86fd17..0ce7c9af40 100644 --- a/templates/user/profile.tmpl +++ b/templates/user/profile.tmpl @@ -39,6 +39,21 @@
{{$.RenderedDescription|Str2html}}
{{end}} + {{if $.RenderedCompetences}} +
  • +
    {{$.RenderedCompetences|Str2html}}
    +
  • + {{end}} + {{if $.RenderedResources}} +
  • +
    {{$.RenderedResources|Str2html}}
    +
  • + {{end}} + {{if $.RenderedInterests}} +
  • +
    {{$.RenderedInterests|Str2html}}
    +
  • + {{end}} {{range .OpenIDs}} {{if .Show}}