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 template
aichy1269839272d9548
diff --git a/cmd/answer/wire_gen.go b/cmd/answer/wire_gen.goindex acee8475..c80d1460 100644--- a/cmd/answer/wire_gen.go+++ b/cmd/answer/wire_gen.go@@ -189,7 +189,9 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database,uiRouter := router.NewUIRouter()authUserMiddleware := middleware.NewAuthUserMiddleware(authService)avatarMiddleware := middleware.NewAvatarMiddleware(serviceConf, uploaderService)- ginEngine := server.NewHTTPServer(debug, staticRouter, answerAPIRouter, swaggerRouter, uiRouter, authUserMiddleware, avatarMiddleware)+ templateController := controller.NewTemplateController()+ templateRouter := router.NewTemplateRouter(templateController)+ ginEngine := server.NewHTTPServer(debug, staticRouter, answerAPIRouter, swaggerRouter, uiRouter, authUserMiddleware, avatarMiddleware, templateRouter)application := newApplication(serverConf, ginEngine)return application, func() {cleanup2()diff --git a/internal/base/server/http.go b/internal/base/server/http.goindex 71220162..82eeb293 100644--- a/internal/base/server/http.go+++ b/internal/base/server/http.go@@ -15,6 +15,7 @@ func NewHTTPServer(debug bool,viewRouter *router.UIRouter,authUserMiddleware *middleware.AuthUserMiddleware,avatarMiddleware *middleware.AvatarMiddleware,+ templateRouter *router.TemplateRouter,) *gin.Engine {if debug {@@ -30,6 +31,7 @@ func NewHTTPServer(debug bool,rootGroup := r.Group("")swaggerRouter.Register(rootGroup)+ templateRouter.RegisterTemplateRouter(rootGroup)static := r.Group("")static.Use(avatarMiddleware.AvatarThumb())staticRouter.RegisterStaticRouter(static)diff --git a/internal/controller/template_controller.go b/internal/controller/template_controller.goindex 625bfa3e..84810397 100644--- a/internal/controller/template_controller.go+++ b/internal/controller/template_controller.go@@ -1,11 +1,88 @@package controller+import (+ "net/http"+ "regexp"++ "github.com/answerdev/answer/ui"+ "github.com/gin-gonic/gin"+)+type TemplateController struct {+ scriptPath string+ cssPath string}// NewTemplateController new controllerfunc NewTemplateController() *TemplateController {- return &TemplateController{}+ script, css := GetStyle()+ return &TemplateController{+ scriptPath: script,+ cssPath: css,+ }+}+func GetStyle() (script, css string) {+ file, err := ui.Build.ReadFile("build/index.html")+ if err != nil {+ return+ }+ scriptRegexp := regexp.MustCompile(`<script defer="defer" src="(.*)"></script>`)+ scriptData := scriptRegexp.FindStringSubmatch(string(file))+ cssRegexp := regexp.MustCompile(`<link href="(.*)" rel="stylesheet">`)+ cssListData := cssRegexp.FindStringSubmatch(string(file))+ if len(scriptData) == 2 {+ script = scriptData[1]+ }+ if len(cssListData) == 2 {+ css = cssListData[1]+ }+ return+}++// Index question list+func (tc *TemplateController) Index(ctx *gin.Context) {+ ctx.JSON(http.StatusOK, gin.H{+ "scriptPath": tc.scriptPath,+ "cssPath": tc.cssPath,+ })+}++// QuestionInfo question and answers info+func (tc *TemplateController) QuestionInfo(ctx *gin.Context) {+ id := ctx.Param("id")+ answerid := ctx.Param("answerid")+ ctx.JSON(http.StatusOK, gin.H{+ "id": id,+ "answerid": answerid,+ "scriptPath": tc.scriptPath,+ "cssPath": tc.cssPath,+ })+}++// TagList tags list+func (tc *TemplateController) TagList(ctx *gin.Context) {+ ctx.JSON(http.StatusOK, gin.H{+ "scriptPath": tc.scriptPath,+ "cssPath": tc.cssPath,+ })}-// func (tc *TemplateController) SearchTagLike(ctx *gin.Context) {+// TagInfo taginfo+func (tc *TemplateController) TagInfo(ctx *gin.Context) {+ tag := ctx.Param("tag")+ ctx.JSON(http.StatusOK, gin.H{+ "tag": tag,+ "scriptPath": tc.scriptPath,+ "cssPath": tc.cssPath,+ })+}++// UserInfo user info+func (tc *TemplateController) UserInfo(ctx *gin.Context) {+ username := ctx.Param("username")+ ctx.JSON(http.StatusOK, gin.H{+ "username": username,+ "scriptPath": tc.scriptPath,+ "cssPath": tc.cssPath,+ })+}diff --git a/internal/router/template_router.go b/internal/router/template_router.goindex d764690a..4ccedb43 100644--- a/internal/router/template_router.go+++ b/internal/router/template_router.go@@ -1,16 +1,31 @@package routerimport (+ "github.com/answerdev/answer/internal/controller""github.com/gin-gonic/gin")type TemplateRouter struct {+ templateController *controller.TemplateController}-func NewTemplateRouter() *TemplateRouter {- return &TemplateRouter{}+func NewTemplateRouter(+ templateController *controller.TemplateController,+) *TemplateRouter {+ return &TemplateRouter{+ templateController: templateController,+ }}// TemplateRouter template router-func (a *TemplateRouter) TemplateRouter(r *gin.RouterGroup) {+func (a *TemplateRouter) RegisterTemplateRouter(r *gin.RouterGroup) {+ r.GET("/", a.templateController.Index)+ r.GET("/index", a.templateController.Index)+ r.GET("/questions", a.templateController.Index)+ r.GET("/questions/:id/", a.templateController.QuestionInfo)+ r.GET("/questions/:id/:title/", a.templateController.QuestionInfo)+ r.GET("/questions/:id/:title/:answerid", a.templateController.QuestionInfo)+ r.GET("/tags", a.templateController.TagList)+ r.GET("/tags/:tag", a.templateController.TagInfo)+ r.GET("/users/:username", a.templateController.UserInfo)}diff --git a/ui/build/index.html b/ui/build/index.htmlindex 1eec7ed2..33e11053 100644--- a/ui/build/index.html+++ b/ui/build/index.html@@ -1 +1 @@-<!doctype html><html><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><link rel="manifest" href="/manifest.json"/><title>Answer</title><script defer="defer" src="/static/js/main.1bed8401.js"></script><link href="/static/css/main.6975b122.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>\ No newline at end of file+<!doctype html><html><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><link rel="manifest" href="/manifest.json"/><title>Answer</title><script defer="defer" src="/static/js/main.1bed8401.js"></script><link href="/static/css/main.6975b122.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>