Платформа ЦРНП "Мирокод" для разработки проектов https://git.mirocod.ru
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

68 lines
1.8 KiB

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)
if trustPropNamesMatches == nil {
return "", err
}
var trustPropsWithSafeURLs = strings.Clone(trustProps)
var trustPropName string
var searchQS string
for _, trustPropNameMatches := range trustPropNamesMatches {
trustPropName = trustPropNameMatches[1]
searchQS = strings.ReplaceAll(trustPropName, " ", "+")
trustPropSubstitutionPattern := fmt.Sprintf(
`- [ ] %s [найти](/explore/%s?tab=&q=%s)`,
trustPropName,
strings.ToLower(fieldName),
searchQS)
trustPropsWithSafeURLs = strings.Replace(trustPropsWithSafeURLs, trustPropNameMatches[0], trustPropSubstitutionPattern, -1)
}
var renderedTrustPropsWithSafeURLs string
renderedTrustPropsWithSafeURLs, err = user.GetRenderedTextFieldByValue(ctx, repo, trustPropsWithSafeURLs)
renderedTrustPropsWithTargetBlank := strings.ReplaceAll(renderedTrustPropsWithSafeURLs, "<a", "<a target='blank'")
return renderedTrustPropsWithTargetBlank, err
}