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")