merge from mindoc-org/mindoc and resolved conflict

This commit is contained in:
shiqstone
2021-04-21 20:40:54 +08:00
64 changed files with 722 additions and 547 deletions

View File

@@ -14,14 +14,15 @@ import (
"io/ioutil"
"path/filepath"
"github.com/astaxie/beego"
"github.com/beego/beego/v2/core/logs"
"github.com/beego/beego/v2/server/web"
"github.com/mindoc-org/mindoc/conf"
"github.com/mindoc-org/mindoc/models"
"github.com/mindoc-org/mindoc/utils"
)
type BaseController struct {
beego.Controller
web.Controller
Member *models.Member
Option map[string]string
EnableAnonymous bool
@@ -75,9 +76,9 @@ func (c *BaseController) Prepare() {
c.EnableAnonymous = strings.EqualFold(c.Option["ENABLE_ANONYMOUS"], "true")
c.EnableDocumentHistory = strings.EqualFold(c.Option["ENABLE_DOCUMENT_HISTORY"], "true")
}
c.Data["HighlightStyle"] = beego.AppConfig.DefaultString("highlight_style", "github")
c.Data["HighlightStyle"] = web.AppConfig.DefaultString("highlight_style", "github")
if b, err := ioutil.ReadFile(filepath.Join(beego.BConfig.WebConfig.ViewsPath, "widgets", "scripts.tpl")); err == nil {
if b, err := ioutil.ReadFile(filepath.Join(web.BConfig.WebConfig.ViewsPath, "widgets", "scripts.tpl")); err == nil {
c.Data["Scripts"] = template.HTML(string(b))
}
@@ -161,18 +162,18 @@ func (c *BaseController) ExecuteViewPathTemplate(tplName string, data interface{
viewPath := c.ViewPath
if c.ViewPath == "" {
viewPath = beego.BConfig.WebConfig.ViewsPath
viewPath = web.BConfig.WebConfig.ViewsPath
}
if err := beego.ExecuteViewPathTemplate(&buf, tplName, viewPath, data); err != nil {
if err := web.ExecuteViewPathTemplate(&buf, tplName, viewPath, data); err != nil {
return "", err
}
return buf.String(), nil
}
func (c *BaseController) BaseUrl() string {
baseUrl := beego.AppConfig.DefaultString("baseurl", "")
baseUrl := web.AppConfig.DefaultString("baseurl", "")
if baseUrl != "" {
if strings.HasSuffix(baseUrl, "/") {
baseUrl = strings.TrimSuffix(baseUrl, "/")
@@ -192,7 +193,7 @@ func (c *BaseController) ShowErrorPage(errCode int, errMsg string) {
var buf bytes.Buffer
if err := beego.ExecuteViewPathTemplate(&buf, "errors/error.tpl", beego.BConfig.WebConfig.ViewsPath, map[string]interface{}{"ErrorMessage": errMsg, "ErrorCode": errCode, "BaseUrl": conf.BaseUrl}); err != nil {
if err := web.ExecuteViewPathTemplate(&buf, "errors/error.tpl", web.BConfig.WebConfig.ViewsPath, map[string]interface{}{"ErrorMessage": errMsg, "ErrorCode": errCode, "BaseUrl": conf.BaseUrl}); err != nil {
c.Abort("500")
}
if errCode >= 200 && errCode <= 510 {