mirror of https://gitee.com/answerdev/answer.git
Merge branch 'feat/0.7.0/seo' into test
This commit is contained in:
commit
703aacf0cf
|
@ -204,7 +204,7 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database,
|
||||||
roleController := controller_backyard.NewRoleController(roleService)
|
roleController := controller_backyard.NewRoleController(roleService)
|
||||||
answerAPIRouter := router.NewAnswerAPIRouter(langController, userController, commentController, reportController, voteController, tagController, followController, collectionController, questionController, answerController, searchController, revisionController, rankController, controller_backyardReportController, userBackyardController, reasonController, themeController, siteInfoController, siteinfoController, notificationController, dashboardController, uploadController, activityController, roleController)
|
answerAPIRouter := router.NewAnswerAPIRouter(langController, userController, commentController, reportController, voteController, tagController, followController, collectionController, questionController, answerController, searchController, revisionController, rankController, controller_backyardReportController, userBackyardController, reasonController, themeController, siteInfoController, siteinfoController, notificationController, dashboardController, uploadController, activityController, roleController)
|
||||||
swaggerRouter := router.NewSwaggerRouter(swaggerConf)
|
swaggerRouter := router.NewSwaggerRouter(swaggerConf)
|
||||||
uiRouter := router.NewUIRouter(siteinfoController)
|
uiRouter := router.NewUIRouter(siteinfoController, siteInfoCommonService)
|
||||||
authUserMiddleware := middleware.NewAuthUserMiddleware(authService, siteInfoCommonService)
|
authUserMiddleware := middleware.NewAuthUserMiddleware(authService, siteInfoCommonService)
|
||||||
avatarMiddleware := middleware.NewAvatarMiddleware(serviceConf, uploaderService)
|
avatarMiddleware := middleware.NewAvatarMiddleware(serviceConf, uploaderService)
|
||||||
templateRenderController := templaterender.NewTemplateRenderController(questionService, userService, tagService, answerService, commentService, dataData, siteInfoCommonService)
|
templateRenderController := templaterender.NewTemplateRenderController(questionService, userService, tagService, answerService, commentService, dataData, siteInfoCommonService)
|
||||||
|
|
|
@ -8,6 +8,8 @@ import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/answerdev/answer/internal/controller"
|
"github.com/answerdev/answer/internal/controller"
|
||||||
|
"github.com/answerdev/answer/internal/service/siteinfo_common"
|
||||||
|
"github.com/answerdev/answer/pkg/htmltext"
|
||||||
"github.com/answerdev/answer/ui"
|
"github.com/answerdev/answer/ui"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/segmentfault/pacman/log"
|
"github.com/segmentfault/pacman/log"
|
||||||
|
@ -20,11 +22,18 @@ const UIStaticPath = "build/static"
|
||||||
// UIRouter is an interface that provides ui static file routers
|
// UIRouter is an interface that provides ui static file routers
|
||||||
type UIRouter struct {
|
type UIRouter struct {
|
||||||
siteInfoController *controller.SiteinfoController
|
siteInfoController *controller.SiteinfoController
|
||||||
|
siteInfoService *siteinfo_common.SiteInfoCommonService
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewUIRouter creates a new UIRouter instance with the embed resources
|
// NewUIRouter creates a new UIRouter instance with the embed resources
|
||||||
func NewUIRouter(siteInfoController *controller.SiteinfoController) *UIRouter {
|
func NewUIRouter(
|
||||||
return &UIRouter{siteInfoController: siteInfoController}
|
siteInfoController *controller.SiteinfoController,
|
||||||
|
siteInfoService *siteinfo_common.SiteInfoCommonService,
|
||||||
|
) *UIRouter {
|
||||||
|
return &UIRouter{
|
||||||
|
siteInfoController: siteInfoController,
|
||||||
|
siteInfoService: siteInfoService,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// _resource is an interface that provides static file, it's a private interface
|
// _resource is an interface that provides static file, it's a private interface
|
||||||
|
@ -74,8 +83,18 @@ func (a *UIRouter) Register(r *gin.Engine) {
|
||||||
filePath := ""
|
filePath := ""
|
||||||
switch urlPath {
|
switch urlPath {
|
||||||
case "/favicon.ico":
|
case "/favicon.ico":
|
||||||
|
branding, err := a.siteInfoService.GetSiteBranding(c)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
}
|
||||||
|
if branding.Favicon != "" {
|
||||||
|
c.String(http.StatusOK, htmltext.GetPicByUrl(branding.Favicon))
|
||||||
|
return
|
||||||
|
} else {
|
||||||
c.Header("content-type", "image/vnd.microsoft.icon")
|
c.Header("content-type", "image/vnd.microsoft.icon")
|
||||||
filePath = UIRootFilePath + urlPath
|
filePath = UIRootFilePath + urlPath
|
||||||
|
|
||||||
|
}
|
||||||
case "/manifest.json":
|
case "/manifest.json":
|
||||||
// filePath = UIRootFilePath + urlPath
|
// filePath = UIRootFilePath + urlPath
|
||||||
a.siteInfoController.GetManifestJson(c)
|
a.siteInfoController.GetManifestJson(c)
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package htmltext
|
package htmltext
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -80,3 +82,16 @@ func FetchExcerpt(html, trimMarker string, limit int) (text string) {
|
||||||
text += trimMarker
|
text += trimMarker
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetPicByUrl(Url string) string {
|
||||||
|
res, err := http.Get(Url)
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
defer res.Body.Close()
|
||||||
|
pix, err := ioutil.ReadAll(res.Body)
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return string(pix)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue