package repo import ( "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/routers/web/user" "errors" "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 = GetRenderedResourcesWithSearchLinks(ctx, repo, "Resources") if err != nil { ctx.ServerError("Render", err) return } ctx.HTML(http.StatusOK, tplResources) } func GetRenderedResourcesWithSearchLinks(ctx *context.Context, repo interface{}, fieldName string) (string, error) { resources := user.GetTextField(repo, fieldName) var regExp *regexp.Regexp var err error regExp, err = regexp.Compile(`- \[ \] (.+)`) if err != nil { return "", err } 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") } var renderedResourcesWithLinks string renderedResourcesWithLinks, err = user.GetRenderedTextFieldByValue(ctx, repo, string(resourcesWithLinks)) return renderedResourcesWithLinks, err }