From b76fbf7d15d23fc65a2f366907bdb6b44e102821 Mon Sep 17 00:00:00 2001 From: Artur Galyamov Date: Fri, 16 Sep 2022 16:48:42 +0500 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=20=D0=B2=D1=8B=D0=B2=D0=BE=D0=B4=20=D0=BA?= =?UTF-8?q?=D0=BE=D0=BC=D0=BF=D0=B5=D1=82=D0=B5=D0=BD=D1=86=D0=B8=D0=B9=20?= =?UTF-8?q?=D1=81=20=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD=D0=BE=D1=81?= =?UTF-8?q?=D1=82=D1=8C=D1=8E=20=D0=B8=D1=81=D0=BA=D0=B0=D1=82=D1=8C=20?= =?UTF-8?q?=D0=B8=D1=85=20#65?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routers/web/repo/competence.go | 3 +-- routers/web/repo/resource.go | 11 +++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/routers/web/repo/competence.go b/routers/web/repo/competence.go index 4282698ce7..1c33a9293b 100644 --- a/routers/web/repo/competence.go +++ b/routers/web/repo/competence.go @@ -3,7 +3,6 @@ package repo import ( "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" - "code.gitea.io/gitea/routers/web/user" "net/http" ) @@ -16,7 +15,7 @@ func Competences(ctx *context.Context) { repo := ctx.Data["Repository"] var err error - ctx.Data["RenderedCompetences"], err = user.GetRenderedTextFieldByName(ctx, repo, "Competences") + ctx.Data["RenderedCompetences"], err = GetRenderedResourcesWithSearchLinks(ctx, repo, "Competences") if err != nil { ctx.ServerError("Render", err) diff --git a/routers/web/repo/resource.go b/routers/web/repo/resource.go index 1aac28328b..d0e5ea569d 100644 --- a/routers/web/repo/resource.go +++ b/routers/web/repo/resource.go @@ -5,8 +5,10 @@ import ( "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/routers/web/user" "errors" + "fmt" "net/http" "regexp" + "strings" ) const ( @@ -18,7 +20,7 @@ func Resources(ctx *context.Context) { repo := ctx.Data["Repository"] var err error - ctx.Data["RenderedResources"], err = getRenderedResourcesWithSearchLinks(ctx, repo) + ctx.Data["RenderedResources"], err = GetRenderedResourcesWithSearchLinks(ctx, repo, "Resources") if err != nil { ctx.ServerError("Render", err) @@ -28,8 +30,8 @@ func Resources(ctx *context.Context) { ctx.HTML(http.StatusOK, tplResources) } -func getRenderedResourcesWithSearchLinks(ctx *context.Context, repo interface{}) (string, error) { - resources := user.GetTextField(repo, "Resources") +func GetRenderedResourcesWithSearchLinks(ctx *context.Context, repo interface{}, fieldName string) (string, error) { + resources := user.GetTextField(repo, fieldName) var regExp *regexp.Regexp var err error @@ -39,7 +41,8 @@ func getRenderedResourcesWithSearchLinks(ctx *context.Context, repo interface{}) return "", err } - resourcesWithLinks := regExp.ReplaceAll([]byte(resources), []byte(`- \[ \] $1 [найти](/explore/resources?tab=&q=$1)`)) + resourceSubstitutionPattern := fmt.Sprintf(`- \[ \] $1 [найти](/explore/%s?tab=&q=$1)`, strings.ToLower(fieldName)) + resourcesWithLinks := regExp.ReplaceAll([]byte(resources), []byte(resourceSubstitutionPattern)) if resourcesWithLinks == nil { return "", errors.New("not found matches in resources")