package repo import ( "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/routers/web/user" "fmt" "net/http" "regexp" "strings" ) const ( tplResources base.TplName = "repo/resources/list" ) func Resources(ctx *context.Context) { ctx.Data["PageIsResources"] = true repo := ctx.Data["Repository"] var err error ctx.Data["RenderedResources"], err = GetRenderedTrustPropsWithSearchLinks(ctx, repo, "Resources") if err != nil { ctx.ServerError("Render", err) return } ctx.HTML(http.StatusOK, tplResources) } func GetRenderedTrustPropsWithSearchLinks(ctx *context.Context, repo interface{}, fieldName string) (string, error) { trustProps := user.GetTextField(repo, fieldName) var regExp *regexp.Regexp var err error regExp, err = regexp.Compile(`- \[ \] (.+)`) if err != nil { return "", err } trustPropNamesMatches := regExp.FindAllStringSubmatch(trustProps, -1) var transformedTrustProps string if trustPropNamesMatches == nil { transformedTrustProps = trustProps } else { transformedTrustProps = strings.Clone(trustProps) var trustPropName string var searchQS string for _, curTrustPropNameMatches := range trustPropNamesMatches { trustPropName = curTrustPropNameMatches[1] searchQS = strings.ReplaceAll(trustPropName, " ", "+") trustPropSubstitutionPattern := fmt.Sprintf( `- [ ] %s [найти](/explore/%s?tab=&q=%s)`, trustPropName, strings.ToLower(fieldName), searchQS) transformedTrustProps = strings.Replace(transformedTrustProps, curTrustPropNameMatches[0], trustPropSubstitutionPattern, -1) } } var renderedTrustPropsWithSafeURLs string renderedTrustPropsWithSafeURLs, err = user.GetRenderedTextFieldByValue(ctx, repo, transformedTrustProps) renderedTrustPropsWithTargetBlank := strings.ReplaceAll(renderedTrustPropsWithSafeURLs, "