From f77d73c83adf2bdd2380d5ba08e076c1d46cfaec Mon Sep 17 00:00:00 2001 From: Artur Galyamov Date: Mon, 19 Sep 2022 17:10:08 +0500 Subject: [PATCH] =?UTF-8?q?=D0=A2=D0=B5=D0=BF=D0=B5=D1=80=D1=8C=20=D1=81?= =?UTF-8?q?=D1=81=D1=8B=D0=BB=D0=BA=D0=B8=20=D0=BD=D0=B0=20=D0=BF=D0=BE?= =?UTF-8?q?=D0=B8=D1=81=D0=BA=20=D0=B4=D0=BE=D0=B2=D0=B5=D1=80=D0=B8=D1=82?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B=D1=85=20=D1=81=D0=B2=D0=BE=D0=B9?= =?UTF-8?q?=D1=81=D1=82=D0=B2=20=D0=BE=D1=82=D0=BA=D1=80=D1=8B=D0=B2=D0=B0?= =?UTF-8?q?=D1=8E=D1=82=D1=81=D1=8F=20=D0=B2=20=D0=BE=D1=82=D0=B4=D0=B5?= =?UTF-8?q?=D0=BB=D1=8C=D0=BD=D0=BE=D0=B9=20=D0=B2=D0=BA=D0=BB=D0=B0=D0=B4?= =?UTF-8?q?=D0=BA=D0=B5=20#65?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit также выполнен рефакторинг, т.к. метод вызывается и для компетенций, и для ресурсов. --- routers/web/repo/competence.go | 2 +- routers/web/repo/resource.go | 34 +++++++++++++++++----------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/routers/web/repo/competence.go b/routers/web/repo/competence.go index 1c33a9293b..5562482324 100644 --- a/routers/web/repo/competence.go +++ b/routers/web/repo/competence.go @@ -15,7 +15,7 @@ func Competences(ctx *context.Context) { repo := ctx.Data["Repository"] var err error - ctx.Data["RenderedCompetences"], err = GetRenderedResourcesWithSearchLinks(ctx, repo, "Competences") + ctx.Data["RenderedCompetences"], err = GetRenderedTrustPropsWithSearchLinks(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 29fa57f164..2499cc0d04 100644 --- a/routers/web/repo/resource.go +++ b/routers/web/repo/resource.go @@ -19,7 +19,7 @@ func Resources(ctx *context.Context) { repo := ctx.Data["Repository"] var err error - ctx.Data["RenderedResources"], err = GetRenderedResourcesWithSearchLinks(ctx, repo, "Resources") + ctx.Data["RenderedResources"], err = GetRenderedTrustPropsWithSearchLinks(ctx, repo, "Resources") if err != nil { ctx.ServerError("Render", err) @@ -29,8 +29,8 @@ func Resources(ctx *context.Context) { ctx.HTML(http.StatusOK, tplResources) } -func GetRenderedResourcesWithSearchLinks(ctx *context.Context, repo interface{}, fieldName string) (string, error) { - resources := user.GetTextField(repo, fieldName) +func GetRenderedTrustPropsWithSearchLinks(ctx *context.Context, repo interface{}, fieldName string) (string, error) { + trustProps := user.GetTextField(repo, fieldName) var regExp *regexp.Regexp var err error @@ -40,29 +40,29 @@ func GetRenderedResourcesWithSearchLinks(ctx *context.Context, repo interface{}, return "", err } - resourceNamesMatches := regExp.FindAllStringSubmatch(resources, -1) - if resourceNamesMatches == nil { + trustPropNamesMatches := regExp.FindAllStringSubmatch(trustProps, -1) + if trustPropNamesMatches == nil { return "", err } - var resourcesWithSafeURLs = strings.Clone(resources) - var resourceName string + var trustPropsWithSafeURLs = strings.Clone(trustProps) + var trustPropName string var searchQS string - for _, resourceNameMatches := range resourceNamesMatches { - resourceName = resourceNameMatches[1] - searchQS = strings.ReplaceAll(resourceName, " ", "+") - resourceSubstitutionPattern := fmt.Sprintf( + for _, trustPropNameMatches := range trustPropNamesMatches { + trustPropName = trustPropNameMatches[1] + searchQS = strings.ReplaceAll(trustPropName, " ", "+") + trustPropSubstitutionPattern := fmt.Sprintf( `- [ ] %s [найти](/explore/%s?tab=&q=%s)`, - resourceName, + trustPropName, strings.ToLower(fieldName), searchQS) - resourcesWithSafeURLs = strings.Replace(resourcesWithSafeURLs, resourceNameMatches[0], resourceSubstitutionPattern, -1) + trustPropsWithSafeURLs = strings.Replace(trustPropsWithSafeURLs, trustPropNameMatches[0], trustPropSubstitutionPattern, -1) } - var renderedResourcesWithSafeURLs string - renderedResourcesWithSafeURLs, err = user.GetRenderedTextFieldByValue(ctx, repo, resourcesWithSafeURLs) - - return renderedResourcesWithSafeURLs, err + var renderedTrustPropsWithSafeURLs string + renderedTrustPropsWithSafeURLs, err = user.GetRenderedTextFieldByValue(ctx, repo, trustPropsWithSafeURLs) + renderedTrustPropsWithTargetBlank := strings.ReplaceAll(renderedTrustPropsWithSafeURLs, "