diff --git a/routers/web/org/home.go b/routers/web/org/home.go index 4967ce0e99..3e9dc97932 100644 --- a/routers/web/org/home.go +++ b/routers/web/org/home.go @@ -5,7 +5,11 @@ package org import ( + "code.gitea.io/gitea/modules/markup" + "code.gitea.io/gitea/modules/markup/markdown" + "fmt" "net/http" + "reflect" "strings" "code.gitea.io/gitea/models" @@ -13,8 +17,6 @@ import ( repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" - "code.gitea.io/gitea/modules/markup" - "code.gitea.io/gitea/modules/markup/markdown" "code.gitea.io/gitea/modules/setting" ) @@ -46,17 +48,24 @@ func Home(ctx *context.Context) { ctx.Data["PageIsUserProfile"] = true ctx.Data["Title"] = org.DisplayName() - if len(org.Description) != 0 { - desc, err := markdown.RenderString(&markup.RenderContext{ - URLPrefix: ctx.Repo.RepoLink, - Metas: map[string]string{"mode": "document"}, - GitRepo: ctx.Repo.GitRepo, - }, org.Description) - if err != nil { - ctx.ServerError("RenderString", err) - return - } - ctx.Data["RenderedDescription"] = desc + + var renderErr error + renderErr = getRenderedTextField(ctx, org, "Description") + if renderErr != nil { + ctx.ServerError("RenderString", renderErr) + return + } + + renderErr = getRenderedTextField(ctx, org, "Competences") + if renderErr != nil { + ctx.ServerError("RenderString", renderErr) + return + } + + renderErr = getRenderedTextField(ctx, org, "Resources") + if renderErr != nil { + ctx.ServerError("RenderString", renderErr) + return } var orderBy db.SearchOrderBy @@ -159,3 +168,32 @@ func Home(ctx *context.Context) { ctx.HTML(http.StatusOK, tplOrgHome) } + +func getTextField(user *models.Organization, fieldName string) string { + reflectedObj := reflect.ValueOf(user) + dynamicField := reflect.Indirect(reflectedObj).FieldByName(fieldName) + return dynamicField.String() +} + +/** +Приходится дублировать код, т.к. не получилось вынести эту функцию и функцию getTextField в services, +т.к. modules/context/context.go зависит от models/user. +*/ +func getRenderedTextField(ctx *context.Context, ctxUser *models.Organization, 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/routers/web/user/profile.go b/routers/web/user/profile.go index 2ad333a6af..d36a68501b 100644 --- a/routers/web/user/profile.go +++ b/routers/web/user/profile.go @@ -6,6 +6,8 @@ package user import ( + "code.gitea.io/gitea/modules/markup" + "code.gitea.io/gitea/modules/markup/markdown" "fmt" "net/http" "path" @@ -17,8 +19,6 @@ import ( repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/context" - "code.gitea.io/gitea/modules/markup" - "code.gitea.io/gitea/modules/markup/markdown" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/routers/web/feed" diff --git a/templates/org/home.tmpl b/templates/org/home.tmpl index 7ba5f95b46..8e1afb08a5 100644 --- a/templates/org/home.tmpl +++ b/templates/org/home.tmpl @@ -11,6 +11,8 @@ {{if $.RenderedDescription}}

{{$.RenderedDescription|Str2html}}

{{end}} + {{if $.RenderedCompetences}}

{{$.RenderedCompetences|Str2html}}

{{end}} + {{if $.RenderedResources}}

{{$.RenderedResources|Str2html}}

{{end}}
{{if .Org.Location}}
{{svg "octicon-location"}} {{.Org.Location}} ({{.Org.LocationCoordinate}})
{{end}} {{if .Org.Website}}
{{svg "octicon-link"}} {{.Org.Website}}
{{end}}