Платформа ЦРНП "Мирокод" для разработки проектов
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.
81 lines
1.8 KiB
81 lines
1.8 KiB
package repo |
|
|
|
import ( |
|
repo_model "code.gitea.io/gitea/models/repo" |
|
"code.gitea.io/gitea/modules/base" |
|
"code.gitea.io/gitea/modules/context" |
|
"code.gitea.io/gitea/modules/markup" |
|
"code.gitea.io/gitea/modules/markup/markdown" |
|
"net/http" |
|
"regexp" |
|
) |
|
|
|
const ( |
|
tplCompetences base.TplName = "repo/competences/list" |
|
) |
|
|
|
func Competences(ctx *context.Context) { |
|
ctx.Data["PageIsCompetences"] = true |
|
repo := ctx.Data["Repository"] |
|
|
|
var err error |
|
ctx.Data["RenderedCompetences"], ctx.Data["TransformedTrustProps"], err = GetRenderedTrustPropsWithSearchLinks(ctx, repo, "Competences") |
|
|
|
if err != nil { |
|
ctx.ServerError("Render", err) |
|
return |
|
} |
|
|
|
ctx.HTML(http.StatusOK, tplCompetences) |
|
} |
|
|
|
func ToggleCompetences(ctx *context.Context) { |
|
if !ctx.IsSigned { |
|
ctx.Error(http.StatusForbidden) |
|
return |
|
} |
|
|
|
repo := ctx.Repo.Repository |
|
toggledContent := ctx.FormString("content") |
|
|
|
content, err := markdown.RenderString(&markup.RenderContext{ |
|
URLPrefix: ctx.FormString("context"), // FIXME: <- IS THIS SAFE ? |
|
Metas: ctx.Repo.Repository.ComposeMetas(), |
|
GitRepo: ctx.Repo.GitRepo, |
|
Ctx: ctx, |
|
}, toggledContent) |
|
if err != nil { |
|
ctx.ServerError("RenderString", err) |
|
return |
|
} |
|
|
|
repo.Competences, err = trimSearchLinks(toggledContent) |
|
if err != nil { |
|
ctx.ServerError("trimSearchLinks", err) |
|
return |
|
} |
|
|
|
err = repo_model.UpdateRepositoryCols(repo, "competences") |
|
if err != nil { |
|
ctx.ServerError("ToggleCompetences", err) |
|
return |
|
} |
|
|
|
responseBody := map[string]interface{}{ |
|
"content": content, |
|
} |
|
|
|
ctx.JSON( |
|
http.StatusOK, |
|
responseBody, |
|
) |
|
} |
|
|
|
func trimSearchLinks(content string) (string, error) { |
|
regExp, err := regexp.Compile(`\s*\[найти\]\(.+\s*\)`) |
|
if err != nil { |
|
return "", err |
|
} |
|
trimmedSearchLink := regExp.ReplaceAllString(content, "") |
|
return trimmedSearchLink, nil |
|
}
|
|
|