From 972d11b0e50c6d2a9c0b32bd875ec48cc2cea99e Mon Sep 17 00:00:00 2001 From: aichy126 <16996097+aichy126@users.noreply.github.com> Date: Wed, 30 Nov 2022 17:39:19 +0800 Subject: [PATCH] update homepage --- internal/base/server/http.go | 6 ++++++ internal/controller/template_controller.go | 16 +++++++++++++--- internal/controller/template_render/tags.go | 5 +++++ ui/template/homepage.html | 9 ++++++++- ui/template/tag-detail.html | 6 +++--- 5 files changed, 35 insertions(+), 7 deletions(-) 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 }}
{{.userinfo.Info.Website}}
+ {{else}} + {{end}}
@@ -39,7 +42,11 @@
About Me
-
{{.bio}}
+ {{if .bio }} +
{{.bio}}
+ {{else}} +
// Hello, World !
+ {{end}}
diff --git a/ui/template/tag-detail.html b/ui/template/tag-detail.html index 2fbf32ed..a6a2fd6d 100644 --- a/ui/template/tag-detail.html +++ b/ui/template/tag-detail.html @@ -4,15 +4,15 @@

- Apple + {{$.tag.SlugName}}

- 对外只有3001一个端口,群集内有负载策略会分发给不同实例1111 + {{templateHTML $.tag.ParsedText}}

-
3 Questions
+
{{.tag.QuestionCount}} Questions