diff --git a/internal/base/server/http.go b/internal/base/server/http.go index aeb11c5c..79d5bb8c 100644 --- a/internal/base/server/http.go +++ b/internal/base/server/http.go @@ -54,6 +54,12 @@ func NewHTTPServer(debug bool, cmsauthV1.Use(authUserMiddleware.CmsAuth()) answerRouter.RegisterAnswerCmsAPIRouter(cmsauthV1) + r.SetFuncMap(template.FuncMap{ + "templateHTML": func(data string) template.HTML { + return template.HTML(data) + }, + }) + dev := os.Getenv("DEVCODE") if dev != "" { r.LoadHTMLGlob("../../ui/template/*") diff --git a/internal/controller/template_controller.go b/internal/controller/template_controller.go index a5aca76f..d1b33152 100644 --- a/internal/controller/template_controller.go +++ b/internal/controller/template_controller.go @@ -9,7 +9,6 @@ import ( templaterender "github.com/answerdev/answer/internal/controller/template_render" "github.com/answerdev/answer/internal/schema" "github.com/answerdev/answer/ui" - "github.com/davecgh/go-spew/spew" "github.com/gin-gonic/gin" ) @@ -84,7 +83,6 @@ func (tc *TemplateController) TagList(ctx *gin.Context) { return } page := templaterender.Paginator(req.Page, req.PageSize, data.Count) - spew.Dump(page) ctx.HTML(http.StatusOK, "tags.html", gin.H{ "scriptPath": tc.scriptPath, "cssPath": tc.cssPath, @@ -96,8 +94,20 @@ func (tc *TemplateController) TagList(ctx *gin.Context) { // TagInfo taginfo func (tc *TemplateController) TagInfo(ctx *gin.Context) { tag := ctx.Param("tag") + + req := &schema.GetTagInfoReq{} + req.Name = tag + taginifo, err := tc.templateRenderController.TagInfo(ctx, req) + if err != nil { + ctx.HTML(http.StatusOK, "404.html", gin.H{ + "scriptPath": tc.scriptPath, + "cssPath": tc.cssPath, + "err": err.Error(), + }) + return + } ctx.HTML(http.StatusOK, "tag-detail.html", gin.H{ - "tag": tag, + "tag": taginifo, "scriptPath": tc.scriptPath, "cssPath": tc.cssPath, }) diff --git a/internal/controller/template_render/tags.go b/internal/controller/template_render/tags.go index 8ff868d1..c7443be6 100644 --- a/internal/controller/template_render/tags.go +++ b/internal/controller/template_render/tags.go @@ -10,3 +10,8 @@ func (q *TemplateRenderController) TagList(ctx context.Context, req *schema.GetT resp, err = q.tagService.GetTagWithPage(ctx, req) return resp, err } + +func (q *TemplateRenderController) TagInfo(ctx context.Context, req *schema.GetTagInfoReq) (resp *schema.GetTagResp, err error) { + resp, err = q.tagService.GetTagInfo(ctx, req) + return resp, err +} diff --git a/ui/template/homepage.html b/ui/template/homepage.html index 7cdab7e4..c9720b61 100644 --- a/ui/template/homepage.html +++ b/ui/template/homepage.html @@ -25,7 +25,10 @@ {{.userinfo.Info.QuestionCount}} questions + {{if .userinfo.Info.Website }}
+ {{else}} + {{end}} @@ -39,7 +42,11 @@- 对外只有3001一个端口,群集内有负载策略会分发给不同实例1111 + {{templateHTML $.tag.ParsedText}}