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