|
|
|
@ -19,7 +19,7 @@ func Resources(ctx *context.Context) {
|
|
|
|
|
repo := ctx.Data["Repository"] |
|
|
|
|
|
|
|
|
|
var err error |
|
|
|
|
ctx.Data["RenderedResources"], err = GetRenderedResourcesWithSearchLinks(ctx, repo, "Resources") |
|
|
|
|
ctx.Data["RenderedResources"], err = GetRenderedTrustPropsWithSearchLinks(ctx, repo, "Resources") |
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
ctx.ServerError("Render", err) |
|
|
|
@ -29,8 +29,8 @@ func Resources(ctx *context.Context) {
|
|
|
|
|
ctx.HTML(http.StatusOK, tplResources) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func GetRenderedResourcesWithSearchLinks(ctx *context.Context, repo interface{}, fieldName string) (string, error) { |
|
|
|
|
resources := user.GetTextField(repo, fieldName) |
|
|
|
|
func GetRenderedTrustPropsWithSearchLinks(ctx *context.Context, repo interface{}, fieldName string) (string, error) { |
|
|
|
|
trustProps := user.GetTextField(repo, fieldName) |
|
|
|
|
|
|
|
|
|
var regExp *regexp.Regexp |
|
|
|
|
var err error |
|
|
|
@ -40,29 +40,29 @@ func GetRenderedResourcesWithSearchLinks(ctx *context.Context, repo interface{},
|
|
|
|
|
return "", err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
resourceNamesMatches := regExp.FindAllStringSubmatch(resources, -1) |
|
|
|
|
if resourceNamesMatches == nil { |
|
|
|
|
trustPropNamesMatches := regExp.FindAllStringSubmatch(trustProps, -1) |
|
|
|
|
if trustPropNamesMatches == nil { |
|
|
|
|
return "", err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var resourcesWithSafeURLs = strings.Clone(resources) |
|
|
|
|
var resourceName string |
|
|
|
|
var trustPropsWithSafeURLs = strings.Clone(trustProps) |
|
|
|
|
var trustPropName string |
|
|
|
|
var searchQS string |
|
|
|
|
|
|
|
|
|
for _, resourceNameMatches := range resourceNamesMatches { |
|
|
|
|
resourceName = resourceNameMatches[1] |
|
|
|
|
searchQS = strings.ReplaceAll(resourceName, " ", "+") |
|
|
|
|
resourceSubstitutionPattern := fmt.Sprintf( |
|
|
|
|
for _, trustPropNameMatches := range trustPropNamesMatches { |
|
|
|
|
trustPropName = trustPropNameMatches[1] |
|
|
|
|
searchQS = strings.ReplaceAll(trustPropName, " ", "+") |
|
|
|
|
trustPropSubstitutionPattern := fmt.Sprintf( |
|
|
|
|
`- [ ] %s [найти](/explore/%s?tab=&q=%s)`, |
|
|
|
|
resourceName, |
|
|
|
|
trustPropName, |
|
|
|
|
strings.ToLower(fieldName), |
|
|
|
|
searchQS) |
|
|
|
|
|
|
|
|
|
resourcesWithSafeURLs = strings.Replace(resourcesWithSafeURLs, resourceNameMatches[0], resourceSubstitutionPattern, -1) |
|
|
|
|
trustPropsWithSafeURLs = strings.Replace(trustPropsWithSafeURLs, trustPropNameMatches[0], trustPropSubstitutionPattern, -1) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var renderedResourcesWithSafeURLs string |
|
|
|
|
renderedResourcesWithSafeURLs, err = user.GetRenderedTextFieldByValue(ctx, repo, resourcesWithSafeURLs) |
|
|
|
|
|
|
|
|
|
return renderedResourcesWithSafeURLs, err |
|
|
|
|
var renderedTrustPropsWithSafeURLs string |
|
|
|
|
renderedTrustPropsWithSafeURLs, err = user.GetRenderedTextFieldByValue(ctx, repo, trustPropsWithSafeURLs) |
|
|
|
|
renderedTrustPropsWithTargetBlank := strings.ReplaceAll(renderedTrustPropsWithSafeURLs, "<a", "<a target='blank'") |
|
|
|
|
return renderedTrustPropsWithTargetBlank, err |
|
|
|
|
} |
|
|
|
|