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.
fix seo page
aichy126783bb31cacbc
diff --git a/internal/controller/template_controller.go b/internal/controller/template_controller.goindex 60eeed24..bfc2299f 100644--- a/internal/controller/template_controller.go+++ b/internal/controller/template_controller.go@@ -115,6 +115,7 @@ func (tc *TemplateController) Index(ctx *gin.Context) {"data": data,"useTitle": UrlUseTitle,"page": templaterender.Paginator(page, req.PageSize, count),+ "path": "questions",})}@@ -147,7 +148,7 @@ func (tc *TemplateController) QuestionList(ctx *gin.Context) {})}-func (tc *TemplateController) QuestionInfo301Jump(ctx *gin.Context, siteInfo *schema.TemplateSiteInfoResp) (jump bool, url string) {+func (tc *TemplateController) QuestionInfo301Jump(ctx *gin.Context, siteInfo *schema.TemplateSiteInfoResp, correctTitle bool) (jump bool, url string) {id := ctx.Param("id")title := ctx.Param("title")titleIsAnswerID := false@@ -168,7 +169,7 @@ func (tc *TemplateController) QuestionInfo301Jump(ctx *gin.Context, siteInfo *screturn true, url} else {//have title- if len(title) > 0 && !titleIsAnswerID {+ if len(title) > 0 && !titleIsAnswerID && correctTitle {return false, ""}detail, err := tc.templateRenderController.QuestionDetail(ctx, id)@@ -184,20 +185,27 @@ func (tc *TemplateController) QuestionInfo301Jump(ctx *gin.Context, siteInfo *sc// QuestionInfo question and answers infofunc (tc *TemplateController) QuestionInfo(ctx *gin.Context) {id := ctx.Param("id")+ title := ctx.Param("title")answerid := ctx.Param("answerid")- siteInfo := tc.SiteInfo(ctx)- jump, jumpurl := tc.QuestionInfo301Jump(ctx, siteInfo)- if jump {- ctx.Redirect(http.StatusMovedPermanently, jumpurl)- return- }+ correctTitle := falsedetail, err := tc.templateRenderController.QuestionDetail(ctx, id)if err != nil {tc.Page404(ctx)return}+ encodeTitle := htmltext.UrlTitle(detail.Title)+ if encodeTitle == title {+ correctTitle = true+ }++ siteInfo := tc.SiteInfo(ctx)+ jump, jumpurl := tc.QuestionInfo301Jump(ctx, siteInfo, correctTitle)+ if jump {+ ctx.Redirect(http.StatusMovedPermanently, jumpurl)+ return+ }// answersanswerReq := &schema.AnswerListReq{@@ -223,7 +231,6 @@ func (tc *TemplateController) QuestionInfo(ctx *gin.Context) {tc.Page404(ctx)return}- encodeTitle := htmltext.UrlTitle(detail.Title)siteInfo.Canonical = fmt.Sprintf("%s/questions/%s/%s", siteInfo.General.SiteUrl, id, encodeTitle)if siteInfo.SiteSeo.PermaLink == schema.PermaLinkQuestionID {siteInfo.Canonical = fmt.Sprintf("%s/questions/%s", siteInfo.General.SiteUrl, id)@@ -242,13 +249,15 @@ func (tc *TemplateController) QuestionInfo(ctx *gin.Context) {answerList := make([]*schema.SuggestedAnswerItem, 0)for _, answer := range answers {if answer.Adopted == schema.AnswerAdoptedEnable {- jsonLD.MainEntity.AcceptedAnswer.Type = "Answer"- jsonLD.MainEntity.AcceptedAnswer.Text = answer.HTML- jsonLD.MainEntity.AcceptedAnswer.UpvoteCount = answer.VoteCount- jsonLD.MainEntity.AcceptedAnswer.URL = fmt.Sprintf("%s/%s", siteInfo.Canonical, answer.ID)- jsonLD.MainEntity.AcceptedAnswer.Author.Type = "Person"- jsonLD.MainEntity.AcceptedAnswer.Author.Name = answer.UserInfo.DisplayName-+ acceptedAnswerItem := &schema.AcceptedAnswerItem{}+ acceptedAnswerItem.Type = "Answer"+ acceptedAnswerItem.Text = answer.HTML+ acceptedAnswerItem.DateCreated = time.Unix(answer.CreateTime, 0)+ acceptedAnswerItem.UpvoteCount = answer.VoteCount+ acceptedAnswerItem.URL = fmt.Sprintf("%s/%s", siteInfo.Canonical, answer.ID)+ acceptedAnswerItem.Author.Type = "Person"+ acceptedAnswerItem.Author.Name = answer.UserInfo.DisplayName+ jsonLD.MainEntity.AcceptedAnswer = acceptedAnswerItem} else {item := &schema.SuggestedAnswerItem{}item.Type = "Answer"@@ -405,6 +414,10 @@ func (tc *TemplateController) html(ctx *gin.Context, code int, tpl string, siteIdata["description"] = siteInfo.Descriptiondata["language"] = handler.GetLang(ctx)data["timezone"] = siteInfo.Interface.TimeZone+ _, ok := data["path"]+ if !ok {+ data["path"] = ""+ }ctx.HTML(code, tpl, data)}diff --git a/internal/schema/template_schema.go b/internal/schema/template_schema.goindex 39f55429..7273f960 100644--- a/internal/schema/template_schema.go+++ b/internal/schema/template_schema.go@@ -24,16 +24,17 @@ type QAPageJsonLD struct {Type string `json:"@type"`Name string `json:"name"`} `json:"author"`- AcceptedAnswer AcceptedAnswerItem `json:"acceptedAnswer"`+ AcceptedAnswer *AcceptedAnswerItem `json:"acceptedAnswer,omitempty"`SuggestedAnswer []*SuggestedAnswerItem `json:"suggestedAnswer"`} `json:"mainEntity"`}type AcceptedAnswerItem struct {- Type string `json:"@type"`- Text string `json:"text"`- UpvoteCount int `json:"upvoteCount"`- URL string `json:"url"`+ Type string `json:"@type"`+ Text string `json:"text"`+ DateCreated time.Time `json:"dateCreated"`+ UpvoteCount int `json:"upvoteCount"`+ URL string `json:"url"`Author struct {Type string `json:"@type"`Name string `json:"name"`diff --git a/ui/template/page.html b/ui/template/page.htmlindex ef37bea5..1faab2f8 100644--- a/ui/template/page.html+++ b/ui/template/page.html@@ -2,26 +2,26 @@<ul class="d-inline-flex mb-0 pagination pagination-sm">{{ if ne .page.Currpage 1 }}<li class="page-item">- <a class="page-link" href="?page={{$.page.Prevpage}}"><span aria-hidden="true">{{translator $.language "ui.pagination.prev"}}</span><span+ <a class="page-link" href="{{$.path}}?page={{$.page.Prevpage}}"><span aria-hidden="true">{{translator $.language "ui.pagination.prev"}}</span><spanclass="visually-hidden">{{translator $.language "ui.pagination.prev"}}</span></a></li>{{ end }}{{ range $value := .page.Pages }}{{ if eq $.page.Currpage $value }}<li class="page-item active">- <span class="page-link" href="?page={{$value}}">{{$value}}+ <span class="page-link" href="{{$.path}}?page={{$value}}">{{$value}}<span class="visually-hidden">(current)</span></span></li>{{ else }}<li class="page-item">- <a class="page-link" href="?page={{$value}}">{{$value}}</a>+ <a class="page-link" href="{{$.path}}?page={{$value}}">{{$value}}</a></li>{{ end }}{{ end }}{{ if lt $.page.Currpage $.page.Totalpages }}<li class="page-item">- <a class="page-link" href="?page={{$.page.Nextpage}}"><span aria-hidden="true">{{translator $.language "ui.pagination.next"}}</span><span+ <a class="page-link" href="{{$.path}}?page={{$.page.Nextpage}}"><span aria-hidden="true">{{translator $.language "ui.pagination.next"}}</span><spanclass="visually-hidden">{{translator $.language "ui.pagination.next"}}</span></a></li>{{ end }}