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.
feat(user): add top questions and answers to user homepage
LinkinStarsce0ec4b806b6
diff --git a/internal/controller/template_controller.go b/internal/controller/template_controller.goindex df10931e..0b22360f 100644--- a/internal/controller/template_controller.go+++ b/internal/controller/template_controller.go@@ -546,12 +546,20 @@ func (tc *TemplateController) UserInfo(ctx *gin.Context) {return}+ questionList, answerList, err := tc.questionService.SearchUserTopList(ctx, req.Username, "")+ if err != nil {+ tc.Page404(ctx)+ return+ }+siteInfo := tc.SiteInfo(ctx)siteInfo.Canonical = fmt.Sprintf("%s/users/%s", siteInfo.General.SiteUrl, username)siteInfo.Title = fmt.Sprintf("%s - %s", username, siteInfo.General.Name)tc.html(ctx, http.StatusOK, "homepage.html", siteInfo, gin.H{- "userinfo": userinfo,- "bio": template.HTML(userinfo.BioHTML),+ "userinfo": userinfo,+ "bio": template.HTML(userinfo.BioHTML),+ "topQuestions": questionList,+ "topAnswers": answerList,})}diff --git a/ui/template/homepage.html b/ui/template/homepage.htmlindex 2f68200d..84887a09 100644--- a/ui/template/homepage.html+++ b/ui/template/homepage.html@@ -63,10 +63,41 @@<div><h5 class="mb-3">{{translator $.language "ui.personal.about_me"}}</h5>{{if .bio }}- <div class="text-center mb-4">{{.bio}}</div>+ <div class="mb-5 text-break fmt">{{.bio}}</div>{{else}}<div class="text-center py-5 mb-4">{{translator $.language "ui.personal.about_me_empty"}}</div>{{end}}+ <div class="mb-4 row">+ <div class="mb-4 col-md-6 col-sm-12">+ <h5 class="mb-3">Top Answers</h5>+ <ol class="list-unstyled">+ {{ range .topAnswers }}+ <li class="mb-2">+ <a class="text-truncate-1" href="{{$.baseURL}}/questions/{{.QuestionID}}/{{.AnswerID}}">{{.QuestionInfo.Title}}</a>+ <div class="text-secondary small">+ <i class="br bi-hand-thumbs-up-fill me-1"></i><span>{{.VoteCount}} votes</span>+ </div>+ </li>+ {{ end }}+ </ol>+ </div>+ <div class="col-md-6 col-sm-12">+ <h5 class="mb-3">Top Questions</h5>+ <ol class="list-unstyled">+ {{ range .topQuestions }}+ <li class="mb-2">+ <a class="text-truncate-1" href="{{$.baseURL}}/questions/{{.ID}}">{{.Title}}</a>+ <div class="text-secondary small">+ <i class="br bi-hand-thumbs-up-fill me-1"></i><span> {{.VoteCount}} votes</span>+ <div class="d-inline-block text-secondary ms-3 small text-success">+ <i class="br bi-check-circle-fill"></i><span> {{.AnswerCount}} answers</span>+ </div>+ </div>+ </li>+ {{ end }}+ </ol>+ </div>+ </div></div></div><div class="mt-5 mt-lg-0 col-xxl-3 col-lg-4 col-sm-12">