Платформа ЦРНП "Мирокод" для разработки проектов
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.
52 lines
1.2 KiB
52 lines
1.2 KiB
package repo |
|
|
|
import ( |
|
"code.gitea.io/gitea/modules/base" |
|
"code.gitea.io/gitea/modules/context" |
|
"code.gitea.io/gitea/routers/web/user" |
|
"errors" |
|
"net/http" |
|
"regexp" |
|
) |
|
|
|
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) |
|
|
|
if err != nil { |
|
ctx.ServerError("Render", err) |
|
return |
|
} |
|
|
|
ctx.HTML(http.StatusOK, tplResources) |
|
} |
|
|
|
func getRenderedResourcesWithSearchLinks(ctx *context.Context, repo interface{}) (string, error) { |
|
resources := user.GetTextField(repo, "Resources") |
|
|
|
var regExp *regexp.Regexp |
|
var err error |
|
|
|
regExp, err = regexp.Compile(`- \[ \] (.+)`) |
|
if err != nil { |
|
return "", err |
|
} |
|
|
|
resourcesWithLinks := regExp.ReplaceAll([]byte(resources), []byte(`- \[ \] $1 [найти](/explore/resources?tab=&q=$1)`)) |
|
|
|
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 |
|
}
|
|
|