This commit is contained in:
aichy126 2022-11-30 18:10:38 +08:00
parent a99a7dd1ce
commit c2b1c60c5b
4 changed files with 24 additions and 9 deletions

View File

@ -1,9 +1,11 @@
package controller
import (
"fmt"
"html/template"
"net/http"
"regexp"
"time"
"github.com/answerdev/answer/internal/base/handler"
templaterender "github.com/answerdev/answer/internal/controller/template_render"
@ -51,9 +53,9 @@ func GetStyle() (script, css string) {
}
return
}
func (tc *TemplateController) SiteInfo(ctx *gin.Context) *schema.SiteInfoResp {
func (tc *TemplateController) SiteInfo(ctx *gin.Context) *schema.TemplateSiteInfoResp {
var err error
resp := &schema.SiteInfoResp{}
resp := &schema.TemplateSiteInfoResp{}
resp.General, err = tc.siteInfoService.GetSiteGeneral(ctx)
if err != nil {
log.Error(err)
@ -67,6 +69,7 @@ func (tc *TemplateController) SiteInfo(ctx *gin.Context) *schema.SiteInfoResp {
if err != nil {
log.Error(err)
}
resp.Year = fmt.Sprintf("%d", time.Now().Year())
return resp
}
@ -99,6 +102,7 @@ func (tc *TemplateController) QuestionInfo(ctx *gin.Context) {
"answerid": answerid,
"scriptPath": tc.scriptPath,
"cssPath": tc.cssPath,
"siteinfo": tc.SiteInfo(ctx),
})
}
@ -114,6 +118,7 @@ func (tc *TemplateController) TagList(ctx *gin.Context) {
"scriptPath": tc.scriptPath,
"cssPath": tc.cssPath,
"err": err.Error(),
"siteinfo": tc.SiteInfo(ctx),
})
return
}
@ -123,6 +128,7 @@ func (tc *TemplateController) TagList(ctx *gin.Context) {
"cssPath": tc.cssPath,
"page": page,
"data": data,
"siteinfo": tc.SiteInfo(ctx),
})
}
@ -138,6 +144,7 @@ func (tc *TemplateController) TagInfo(ctx *gin.Context) {
"scriptPath": tc.scriptPath,
"cssPath": tc.cssPath,
"err": err.Error(),
"siteinfo": tc.SiteInfo(ctx),
})
return
}
@ -145,6 +152,7 @@ func (tc *TemplateController) TagInfo(ctx *gin.Context) {
"tag": taginifo,
"scriptPath": tc.scriptPath,
"cssPath": tc.cssPath,
"siteinfo": tc.SiteInfo(ctx),
})
}
@ -156,6 +164,7 @@ func (tc *TemplateController) UserInfo(ctx *gin.Context) {
userinfo, err := tc.templateRenderController.UserInfo(ctx, req)
if err != nil {
ctx.HTML(http.StatusNotFound, "404.html", gin.H{
"siteinfo": tc.SiteInfo(ctx),
"scriptPath": tc.scriptPath,
"cssPath": tc.cssPath,
"err": err.Error(),
@ -163,6 +172,7 @@ func (tc *TemplateController) UserInfo(ctx *gin.Context) {
return
}
ctx.HTML(http.StatusOK, "homepage.html", gin.H{
"siteinfo": tc.SiteInfo(ctx),
"userinfo": userinfo,
"scriptPath": tc.scriptPath,
"cssPath": tc.cssPath,
@ -172,6 +182,7 @@ func (tc *TemplateController) UserInfo(ctx *gin.Context) {
func (tc *TemplateController) Page404(ctx *gin.Context) {
ctx.HTML(http.StatusNotFound, "404.html", gin.H{
"siteinfo": tc.SiteInfo(ctx),
"scriptPath": tc.scriptPath,
"cssPath": tc.cssPath,
})

View File

@ -95,6 +95,12 @@ type SiteInfoResp struct {
Interface *SiteInterfaceResp `json:"interface"`
Branding *SiteBrandingResp `json:"branding"`
}
type TemplateSiteInfoResp struct {
General *SiteGeneralResp `json:"general"`
Interface *SiteInterfaceResp `json:"interface"`
Branding *SiteBrandingResp `json:"branding"`
Year string
}
// UpdateSMTPConfigReq get smtp config request
type UpdateSMTPConfigReq struct {

View File

@ -5,8 +5,8 @@
<div class="container">
<p class="text-center mb-0 fs-14 text-secondary">
Built on <a href="https://answer.dev/" target="_blank"> Answer </a>-
the open-source software that power Q&amp;A communities<br />Made
with love © 2022 Answer
the open-source software that power Q&amp;A communities.<br />Made
with love © {{.siteinfo.Year}} {{.siteinfo.General.Name}}.
</p>
</div>
</footer>

View File

@ -20,11 +20,9 @@
<span class="navbar-toggler-icon"></span>
</button>
<div class="d-flex justify-content-between align-items-center nav-grow flex-nowrap">
<a class="lh-1 me-0 me-sm-3 navbar-brand" href="/"><img
class="d-none d-lg-block logo rounded-1 me-0"
src="https://answer.dev.segmentfault.com/uploads/branding/4Gud8KXBXA9.png" alt="" /><img
class="lg-none logo rounded-1 me-0"
src="https://answer.dev.segmentfault.com/uploads/branding/4GxqyBKy6hu.png" alt="" /></a>
<a class="lh-1 me-0 me-sm-3 navbar-brand" href="/">
{{.siteinfo.General.Name}}
</a>
</div>
<div class="me-auto navbar-collapse collapse" id="navBarContent">
<hr class="hr lg-none mb-2" style="margin-top: 12px" />