Skip to content

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 homepage

aichy126972d11b0e50c
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 @@
<strong class="fs-5">{{.userinfo.Info.QuestionCount}}</strong><span class="text-secondary"> questions</span>
</div>
</div>
+ {{if .userinfo.Info.Website }}
<div class="d-flex align-items-center"><i class="br bi-house-door-fill me-2"></i><a class="link-secondary" href="{{.userinfo.Info.Website}}">{{.userinfo.Info.Website}}</a></div>
+ {{else}}
+ {{end}}
<div class="d-flex text-secondary"></div>
</div>
</div>
@@ -39,7 +42,11 @@
<div class="col-xxl-7 col-lg-8 col-sm-12">
<div>
<h5 class="mb-3">About Me</h5>
- <div class="text-center py-5 mb-4">{{.bio}}</div>
+ {{if .bio }}
+ <div class="text-center mb-4">{{.bio}}</div>
+ {{else}}
+ <div class="text-center py-5 mb-4">// Hello, World !</div>
+ {{end}}
</div>
</div>
<div class="mt-5 mt-lg-0 col-xxl-3 col-lg-4 col-sm-12">
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 @@
<div class="col-xxl-7 col-lg-8 col-sm-12">
<div class="tag-box mb-5">
<h3 class="mb-3">
- <a class="link-dark" href="/tags/apple">Apple</a>
+ <a class="link-dark" href="/tags/{{$.tag.SlugName}}">{{$.tag.SlugName}}</a>
</h3>
<p class="text-break">
- 对外只有3001一个端口,群集内有负载策略会分发给不同实例1111
+ {{templateHTML $.tag.ParsedText}}
</p>
</div>
<div>
<div class="mb-3 d-flex flex-wrap justify-content-between">
- <h5 class="fs-5 text-nowrap mb-3 mb-md-0">3 Questions</h5>
+ <h5 class="fs-5 text-nowrap mb-3 mb-md-0">{{.tag.QuestionCount}} Questions</h5>
</div>
<div class="border-top border-bottom-0 list-group list-group-flush">
<div class="border-bottom pt-3 pb-2 px-0 list-group-item">