Browse Source

Реализован вывод компетенций с возможностью искать их #65

pull/120/head
Artur Galyamov 2 years ago
parent
commit
b76fbf7d15
  1. 3
      routers/web/repo/competence.go
  2. 11
      routers/web/repo/resource.go

3
routers/web/repo/competence.go

@ -3,7 +3,6 @@ package repo
import (
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/routers/web/user"
"net/http"
)
@ -16,7 +15,7 @@ func Competences(ctx *context.Context) {
repo := ctx.Data["Repository"]
var err error
ctx.Data["RenderedCompetences"], err = user.GetRenderedTextFieldByName(ctx, repo, "Competences")
ctx.Data["RenderedCompetences"], err = GetRenderedResourcesWithSearchLinks(ctx, repo, "Competences")
if err != nil {
ctx.ServerError("Render", err)

11
routers/web/repo/resource.go

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

Loading…
Cancel
Save