TagInfo taginfo
(ctx *gin.Context)
| 470 | |
| 471 | // TagInfo taginfo |
| 472 | func (tc *TemplateController) TagInfo(ctx *gin.Context) { |
| 473 | tag := ctx.Param("tag") |
| 474 | req := &schema.GetTamplateTagInfoReq{} |
| 475 | if handler.BindAndCheck(ctx, req) { |
| 476 | tc.Page404(ctx) |
| 477 | return |
| 478 | } |
| 479 | nowPage := req.Page |
| 480 | req.Name = tag |
| 481 | tagInfo, questionList, questionCount, err := tc.templateRenderController.TagInfo(ctx, req) |
| 482 | if err != nil { |
| 483 | tc.Page404(ctx) |
| 484 | return |
| 485 | } |
| 486 | page := templaterender.Paginator(nowPage, req.PageSize, questionCount) |
| 487 | |
| 488 | siteInfo := tc.SiteInfo(ctx) |
| 489 | siteInfo.Canonical = fmt.Sprintf("%s/tags/%s", siteInfo.General.SiteUrl, tag) |
| 490 | if req.Page > 1 { |
| 491 | siteInfo.Canonical = fmt.Sprintf("%s/tags/%s?page=%d", siteInfo.General.SiteUrl, tag, req.Page) |
| 492 | } |
| 493 | siteInfo.Description = htmltext.FetchExcerpt(tagInfo.ParsedText, "...", 240) |
| 494 | if len(tagInfo.ParsedText) == 0 { |
| 495 | siteInfo.Description = translator.Tr(handler.GetLangByCtx(ctx), constant.TagHasNoDescription) |
| 496 | } |
| 497 | siteInfo.Keywords = tagInfo.DisplayName |
| 498 | |
| 499 | UrlUseTitle := siteInfo.SiteSeo.Permalink == constant.PermalinkQuestionIDAndTitle || |
| 500 | siteInfo.SiteSeo.Permalink == constant.PermalinkQuestionIDAndTitleByShortID |
| 501 | |
| 502 | siteInfo.Title = fmt.Sprintf("'%s' %s - %s", tagInfo.DisplayName, translator.Tr(handler.GetLangByCtx(ctx), constant.QuestionsTitleTrKey), siteInfo.General.Name) |
| 503 | tc.html(ctx, http.StatusOK, "tag-detail.html", siteInfo, gin.H{ |
| 504 | "tag": tagInfo, |
| 505 | "questionList": questionList, |
| 506 | "questionCount": questionCount, |
| 507 | "useTitle": UrlUseTitle, |
| 508 | "page": page, |
| 509 | }) |
| 510 | } |
| 511 | |
| 512 | // UserInfo user info |
| 513 | func (tc *TemplateController) UserInfo(ctx *gin.Context) { |
nothing calls this directly
no test coverage detected