A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.
update seo template
aichy1265fc73a327764
diff --git a/internal/base/server/http_funcmap.go b/internal/base/server/http_funcmap.goindex c5f58f45..8116842a 100644--- a/internal/base/server/http_funcmap.go+++ b/internal/base/server/http_funcmap.go@@ -9,6 +9,7 @@ import ("time""github.com/answerdev/answer/internal/base/translator"+ "github.com/answerdev/answer/internal/controller""github.com/answerdev/answer/internal/schema""github.com/answerdev/answer/pkg/converter""github.com/answerdev/answer/pkg/day"@@ -41,6 +42,9 @@ var funcMap = template.FuncMap{"templateHTML": func(data string) template.HTML {return template.HTML(data)},+ "formatLinkNofollow": func(data string) template.HTML {+ return template.HTML(FormatLinkNofollow(data))+ },"translator": func(la i18n.Language, data string, params ...interface{}) string {trans := translator.GlobalTrans.Tr(la, data)@@ -116,3 +120,21 @@ var funcMap = template.FuncMap{return htmltext.UrlTitle(title)},}++func FormatLinkNofollow(html string) string {+ var hrefRegexp = regexp.MustCompile("(?m)<a.*?[^<]>.*?</a>")+ match := hrefRegexp.FindAllString(html, -1)+ if match != nil {+ for _, v := range match {+ hasNofollow := strings.Contains(v, "rel=\"nofollow\"")+ hasSiteUrl := strings.Contains(v, controller.SiteUrl)+ if !hasSiteUrl {+ if !hasNofollow {+ nofollowUrl := strings.Replace(v, "<a", "<a rel=\"nofollow\"", 1)+ html = strings.Replace(html, v, nofollowUrl, 1)+ }+ }+ }+ }+ return html+}diff --git a/internal/controller/template_controller.go b/internal/controller/template_controller.goindex b57df849..0d4bd3f0 100644--- a/internal/controller/template_controller.go+++ b/internal/controller/template_controller.go@@ -23,6 +23,8 @@ import ("github.com/segmentfault/pacman/log")+var SiteUrl = ""+type TemplateController struct {scriptPath stringcssPath string@@ -67,6 +69,7 @@ func (tc *TemplateController) SiteInfo(ctx *gin.Context) *schema.TemplateSiteInfif err != nil {log.Error(err)}+ SiteUrl = resp.General.SiteUrlresp.Interface, err = tc.siteInfoService.GetSiteInterface(ctx)if err != nil {log.Error(err)diff --git a/pkg/converter/markdown.go b/pkg/converter/markdown.goindex 97a469d4..d066b030 100644--- a/pkg/converter/markdown.go+++ b/pkg/converter/markdown.go@@ -37,6 +37,7 @@ func Markdown2HTML(source string) string {filter.AllowStyling()filter.RequireNoFollowOnLinks(false)filter.RequireParseableURLs(false)+ filter.RequireNoFollowOnFullyQualifiedLinks(false)html = filter.Sanitize(html)return html}diff --git a/ui/template/comment.html b/ui/template/comment.htmlindex 26936b2d..3ebd8ba1 100644--- a/ui/template/comment.html+++ b/ui/template/comment.html@@ -3,7 +3,7 @@<div class="border-bottom py-2 comment-item border-top"><div class="d-block"><div class="fmt fs-14">- {{templateHTML .ParsedText}}+ {{formatLinkNofollow .ParsedText}}</div></div><div class="d-flex justify-content-between fs-14">diff --git a/ui/template/question-detail.html b/ui/template/question-detail.htmlindex b1866d1c..ad46ca6b 100644--- a/ui/template/question-detail.html+++ b/ui/template/question-detail.html@@ -28,7 +28,7 @@{{end}}</div><article class="fmt text-break text-wrap mt-4">- {{templateHTML .detail.HTML}}+ {{formatLinkNofollow .detail.HTML}}</article><div class="mt-4"><div role="group" class="btn-group">@@ -98,7 +98,7 @@{{range .answers}}<div id="10020000000000930" class="answer-item py-4"><article class="fmt">- {{templateHTML .HTML}}+ {{formatLinkNofollow .HTML}}</article><div class="d-flex align-items-center mt-4"><div class="">diff --git a/ui/template/tag-detail.html b/ui/template/tag-detail.htmlindex 1ed561e3..511e63d3 100644--- a/ui/template/tag-detail.html+++ b/ui/template/tag-detail.html@@ -8,7 +8,7 @@>{{$.tag.SlugName}}</a></h3>- <p class="text-break">{{templateHTML $.tag.ParsedText}}</p>+ <p class="text-break">{{formatLinkNofollow $.tag.ParsedText}}</p></div><div><div class="mb-3 d-flex flex-wrap justify-content-between">