mirror of https://github.com/mindoc-org/mindoc.git
parent
c0c3db6c50
commit
327d6fb8d8
|
@ -43,7 +43,7 @@ func RegisterDataBase() {
|
|||
if err == nil {
|
||||
orm.DefaultTimeLoc = location
|
||||
} else {
|
||||
beego.Error("加载时区配置信息失败,请检查是否存在ZONEINFO环境变量:", err)
|
||||
beego.Error("加载时区配置信息失败,请检查是否存在ZONEINFO环境变量->", err)
|
||||
}
|
||||
|
||||
port := beego.AppConfig.String("db_port")
|
||||
|
@ -51,7 +51,7 @@ func RegisterDataBase() {
|
|||
dataSource := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=true&loc=%s", username, password, host, port, database, url.QueryEscape(timezone))
|
||||
|
||||
if err := orm.RegisterDataBase("default", "mysql", dataSource); err != nil {
|
||||
beego.Error("注册默认数据库失败:", err)
|
||||
beego.Error("注册默认数据库失败->", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
} else if adapter == "sqlite3" {
|
||||
|
@ -67,7 +67,7 @@ func RegisterDataBase() {
|
|||
err := orm.RegisterDataBase("default", "sqlite3", database)
|
||||
|
||||
if err != nil {
|
||||
beego.Error("注册默认数据库失败:", err)
|
||||
beego.Error("注册默认数据库失败->", err)
|
||||
}
|
||||
} else {
|
||||
beego.Error("不支持的数据库类型.")
|
||||
|
@ -252,6 +252,7 @@ func ResolveCommand(args []string) {
|
|||
if err := beego.LoadAppConfig("ini", conf.ConfigurationFile);err != nil {
|
||||
log.Fatal("An error occurred:", err)
|
||||
}
|
||||
conf.AutoLoadDelay = beego.AppConfig.DefaultInt("config_auto_delay",0)
|
||||
uploads := conf.WorkingDir("uploads")
|
||||
|
||||
os.MkdirAll(uploads, 0666)
|
||||
|
@ -374,6 +375,40 @@ func RegisterCache() {
|
|||
beego.Info("缓存初始化完成.")
|
||||
}
|
||||
|
||||
//自动加载配置文件.修改了监听端口号和数据库配置无法自动生效.
|
||||
func RegisterAutoLoadConfig() {
|
||||
if conf.AutoLoadDelay > 0 {
|
||||
ticker := time.NewTicker(time.Second * time.Duration(conf.AutoLoadDelay))
|
||||
|
||||
go func() {
|
||||
f,err := os.Stat(conf.ConfigurationFile)
|
||||
if err != nil {
|
||||
beego.Error("读取配置文件时出错 ->",err)
|
||||
return
|
||||
}
|
||||
modTime := f.ModTime()
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
f,err := os.Stat(conf.ConfigurationFile)
|
||||
if err != nil {
|
||||
beego.Error("读取配置文件时出错 ->",err)
|
||||
break
|
||||
}
|
||||
if modTime != f.ModTime() {
|
||||
if err := beego.LoadAppConfig("ini", conf.ConfigurationFile); err != nil {
|
||||
beego.Error("An error occurred:", err)
|
||||
break
|
||||
}
|
||||
modTime = f.ModTime()
|
||||
beego.Info("配置文件已加载")
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
||||
if configPath, err := filepath.Abs(conf.ConfigurationFile); err == nil {
|
||||
|
|
|
@ -47,6 +47,8 @@ func (d *Daemon) Run() {
|
|||
|
||||
commands.RegisterFunction()
|
||||
|
||||
commands.RegisterAutoLoadConfig()
|
||||
|
||||
beego.ErrorController(&controllers.ErrorController{})
|
||||
|
||||
fmt.Printf("MinDoc version => %s\nbuild time => %s\nstart directory => %s\n%s\n", conf.VERSION, conf.BUILD_TIME, os.Args[0], conf.GO_VERSION)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
appname = godoc
|
||||
appname = mindoc
|
||||
# httpaddr = 127.0.0.1
|
||||
httpport = 8181
|
||||
runmode = dev
|
||||
|
@ -10,6 +10,15 @@ baseurl=
|
|||
#默认Session生成Key的秘钥
|
||||
beegoserversessionkey=123456
|
||||
|
||||
#########代码高亮样式################
|
||||
#样式演示地址:https://highlightjs.org/static/demo/
|
||||
highlight_style=github
|
||||
|
||||
########配置文件自动加载##################
|
||||
#大于0时系统会自动检测配置文件是否变动,变动后自动加载并生效,单位是秒。监听端口和数据库配置无效
|
||||
config_auto_delay=0
|
||||
|
||||
|
||||
########Session储存方式##############
|
||||
#以文件方式储存
|
||||
sessionprovider=file
|
||||
|
|
|
@ -68,6 +68,7 @@ var (
|
|||
WorkingDirectory = "./"
|
||||
LogFile = "./runtime/logs"
|
||||
BaseUrl = ""
|
||||
AutoLoadDelay = 0
|
||||
)
|
||||
|
||||
// app_key
|
||||
|
|
|
@ -77,6 +77,7 @@ func (c *BaseController) Prepare() {
|
|||
}
|
||||
}
|
||||
}
|
||||
c.Data["HighlightStyle"] = beego.AppConfig.DefaultString("highlight_style","github")
|
||||
}
|
||||
|
||||
// SetMember 获取或设置当前登录用户信息,如果 MemberId 小于 0 则标识删除 Session
|
||||
|
|
|
@ -44,15 +44,15 @@ func (c *LabelController) Index() {
|
|||
c.Abort("500")
|
||||
}
|
||||
}
|
||||
member_id := 0
|
||||
memberId := 0
|
||||
if c.Member != nil {
|
||||
member_id = c.Member.MemberId
|
||||
memberId = c.Member.MemberId
|
||||
}
|
||||
searchResult, totalCount, err := models.NewBook().FindForLabelToPager(labelName, pageIndex, conf.PageSize, member_id)
|
||||
searchResult, totalCount, err := models.NewBook().FindForLabelToPager(labelName, pageIndex, conf.PageSize, memberId)
|
||||
|
||||
if err != nil {
|
||||
beego.Error(err)
|
||||
return
|
||||
if err != nil && err != orm.ErrNoRows {
|
||||
beego.Error("查询标签时出错 ->", err)
|
||||
c.ShowErrorPage(500, "查询文档列表时出错")
|
||||
}
|
||||
if totalCount > 0 {
|
||||
pager := pagination.NewPagination(c.Ctx.Request, totalCount, conf.PageSize, c.BaseUrl())
|
||||
|
@ -74,8 +74,8 @@ func (c *LabelController) List() {
|
|||
|
||||
labels, totalCount, err := models.NewLabel().FindToPager(pageIndex, pageSize)
|
||||
|
||||
if err != nil {
|
||||
c.ShowErrorPage(50001, err.Error())
|
||||
if err != nil && err != orm.ErrNoRows {
|
||||
c.ShowErrorPage(500, err.Error())
|
||||
}
|
||||
if totalCount > 0 {
|
||||
pager := pagination.NewPagination(c.Ctx.Request, totalCount, conf.PageSize, c.BaseUrl())
|
||||
|
|
|
@ -108,6 +108,10 @@ func (m *Attachment) FindToPager(pageIndex, pageSize int) (attachList []*Attachm
|
|||
_, err = o.QueryTable(m.TableNameWithPrefix()).OrderBy("-attachment_id").Offset(offset).Limit(pageSize).All(&list)
|
||||
|
||||
if err != nil {
|
||||
if err == orm.ErrNoRows {
|
||||
beego.Info("没有查到附件 ->",err)
|
||||
err = nil
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -180,9 +180,9 @@ func (m *Document) RemoveCache() {
|
|||
func (m *Document) FromCacheById(id int) (*Document, error) {
|
||||
|
||||
var doc Document
|
||||
if err := cache.Get("Document.Id."+strconv.Itoa(id), &m); err == nil {
|
||||
if err := cache.Get("Document.Id."+strconv.Itoa(id), &m); err == nil && m.DocumentId > 0 {
|
||||
m = &doc
|
||||
beego.Info("从缓存中获取文档信息成功", m.DocumentId)
|
||||
beego.Info("从缓存中获取文档信息成功 ->", m.DocumentId)
|
||||
return m, nil
|
||||
}
|
||||
|
||||
|
@ -202,8 +202,8 @@ func (m *Document) FromCacheByIdentify(identify string, bookId int) (*Document,
|
|||
|
||||
key := fmt.Sprintf("Document.BookId.%d.Identify.%s", bookId, identify)
|
||||
|
||||
if err := cache.Get(key,m); err == nil {
|
||||
beego.Info("从缓存中获取文档信息成功", key)
|
||||
if err := cache.Get(key,m); err == nil && m.DocumentId > 0 {
|
||||
beego.Info("从缓存中获取文档信息成功 ->", key)
|
||||
return m, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"github.com/astaxie/beego/orm"
|
||||
"github.com/lifei6671/mindoc/conf"
|
||||
"strings"
|
||||
"github.com/astaxie/beego"
|
||||
)
|
||||
|
||||
type Label struct {
|
||||
|
@ -98,6 +99,11 @@ func (m *Label) FindToPager(pageIndex, pageSize int) (labels []*Label, totalCoun
|
|||
|
||||
_, err = o.QueryTable(m.TableNameWithPrefix()).OrderBy("-book_number").Offset(offset).Limit(pageSize).All(&labels)
|
||||
|
||||
if err == orm.ErrNoRows {
|
||||
beego.Info("没有查询到标签 ->",err)
|
||||
err = nil
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -36,18 +36,6 @@
|
|||
.editormd-preview-container table tr {
|
||||
background-color: #fff
|
||||
}
|
||||
.editormd-preview-container code {
|
||||
padding: .2em 0;
|
||||
margin-left: 3px;
|
||||
margin-right: 3px;
|
||||
background-color: #eee;
|
||||
border-radius: 3px;
|
||||
font-size: 1em;
|
||||
font-family: Consolas,"Liberation Mono",Menlo,Courier,'Microsoft Yahei',monospace;
|
||||
border: 0;
|
||||
color: #555;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
/**************TOC*******************/
|
||||
.markdown-toc{
|
||||
|
@ -56,17 +44,35 @@
|
|||
}
|
||||
/***********代码样式*****************/
|
||||
.markdown-body .highlight pre, .markdown-body pre{
|
||||
padding: 0;
|
||||
font-size: 12px;
|
||||
border-radius:0;
|
||||
line-height: 1.4em;
|
||||
padding: 1em;
|
||||
border: none;
|
||||
overflow: auto;
|
||||
line-height: 1.45;
|
||||
max-height: 35em;
|
||||
position: relative;
|
||||
/*background: url(../editor.md/lib/highlight/blueprint.png) #F6F6F6;*/
|
||||
-moz-background-size: 30px,30px;
|
||||
-o-background-size: 30px,30px;
|
||||
-webkit-background-size: 30px,30px;
|
||||
background-size: 30px,30px;
|
||||
border-radius:4px;
|
||||
word-break:break-all;
|
||||
word-wrap:break-word;
|
||||
}
|
||||
.editormd-preview-container pre.hljs>code {
|
||||
border-radius: 3px;
|
||||
font-size: 1.1em;
|
||||
font-family: "Source Code Pro",Consolas,"Liberation Mono",Menlo,Courier,'Microsoft Yahei',monospace;
|
||||
border: 0;
|
||||
word-break: break-all;
|
||||
overflow-y: auto; overflow-x: hidden;
|
||||
overflow-wrap: normal;
|
||||
white-space: inherit
|
||||
}
|
||||
.editormd-preview-container pre.prettyprint, .editormd-html-preview pre.prettyprint {
|
||||
padding: 0;
|
||||
}
|
||||
.hljs{
|
||||
padding: 10px 15px !important;
|
||||
}
|
||||
|
||||
.editormd-preview-container ol.linenums, .editormd-html-preview ol.linenums{
|
||||
color: #999;
|
||||
}
|
||||
|
|
|
@ -3636,7 +3636,6 @@
|
|||
overflow: auto;
|
||||
font-size: 85%;
|
||||
line-height: 1.45;
|
||||
background-color: #f7f7f7;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
|
@ -3657,7 +3656,6 @@
|
|||
overflow: initial;
|
||||
line-height: inherit;
|
||||
word-wrap: normal;
|
||||
background-color: transparent;
|
||||
border: 0;
|
||||
}
|
||||
|
||||
|
@ -3865,7 +3863,6 @@
|
|||
}
|
||||
.editormd-preview-container pre, .editormd-html-preview pre {
|
||||
border: 1px solid #ddd;
|
||||
background: #f6f6f6;
|
||||
padding: 10px;
|
||||
-webkit-border-radius: 3px;
|
||||
-moz-border-radius: 3px;
|
||||
|
|
|
@ -2920,7 +2920,6 @@
|
|||
overflow: auto;
|
||||
font-size: 85%;
|
||||
line-height: 1.45;
|
||||
background-color: #f7f7f7;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
|
@ -2941,7 +2940,6 @@
|
|||
overflow: initial;
|
||||
line-height: inherit;
|
||||
word-wrap: normal;
|
||||
background-color: transparent;
|
||||
border: 0;
|
||||
}
|
||||
|
||||
|
@ -3149,7 +3147,6 @@
|
|||
}
|
||||
.editormd-preview-container pre, .editormd-html-preview pre {
|
||||
border: 1px solid #ddd;
|
||||
background: #f6f6f6;
|
||||
padding: 10px;
|
||||
-webkit-border-radius: 3px;
|
||||
-moz-border-radius: 3px;
|
||||
|
|
|
@ -26,7 +26,9 @@
|
|||
var cmAddonPath = "codemirror/addon/";
|
||||
|
||||
var codeMirrorModules = [
|
||||
"jquery", "marked", "prettify",
|
||||
"jquery", "marked",
|
||||
//"prettify",
|
||||
"highlight/highlight",
|
||||
"katex", "raphael", "underscore", "flowchart", "jqueryflowchart", "sequenceDiagram",
|
||||
|
||||
"codemirror/lib/codemirror",
|
||||
|
@ -239,6 +241,7 @@
|
|||
flowChart : false, // flowChart.js only support IE9+
|
||||
sequenceDiagram : false, // sequenceDiagram.js only support IE9+
|
||||
previewCodeHighlight : true,
|
||||
highlightStyle : "github",
|
||||
|
||||
toolbar : true, // show/hide toolbar
|
||||
toolbarAutoFixed : true, // on window scroll auto fixed position
|
||||
|
@ -653,7 +656,10 @@
|
|||
|
||||
if (settings.previewCodeHighlight)
|
||||
{
|
||||
editormd.loadScript(loadPath + "prettify.min", function() {
|
||||
// editormd.loadScript(loadPath + "prettify.min", function() {
|
||||
// loadFlowChartOrSequenceDiagram();
|
||||
// });
|
||||
editormd.loadScript(loadPath + "highlight/highlight", function() {
|
||||
loadFlowChartOrSequenceDiagram();
|
||||
});
|
||||
}
|
||||
|
@ -1543,11 +1549,16 @@
|
|||
|
||||
if (settings.previewCodeHighlight)
|
||||
{
|
||||
previewContainer.find("pre").addClass("prettyprint linenums");
|
||||
|
||||
if (typeof prettyPrint !== "undefined")
|
||||
{
|
||||
prettyPrint();
|
||||
// previewContainer.find("pre").addClass("prettyprint");
|
||||
//
|
||||
// if (typeof prettyPrint !== "undefined")
|
||||
// {
|
||||
// prettyPrint();
|
||||
// }
|
||||
if (typeof hljs !== "undefined") {
|
||||
previewContainer.find('pre').each(function (i, block) {
|
||||
hljs.highlightBlock(block);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4064,8 +4075,11 @@
|
|||
|
||||
if (settings.previewCodeHighlight)
|
||||
{
|
||||
div.find("pre").addClass("prettyprint linenums");
|
||||
prettyPrint();
|
||||
//div.find("pre").addClass("prettyprint");
|
||||
//prettyPrint();
|
||||
div.find("pre").each(function (i, block) {
|
||||
hljs.highlightBlock(block);
|
||||
});
|
||||
}
|
||||
|
||||
if (!editormd.isIE8)
|
||||
|
|
|
@ -581,9 +581,13 @@
|
|||
|
||||
editormd.$marked = marked;
|
||||
|
||||
if(!settings.highlightStyle){
|
||||
settings.highlightStyle = "github";
|
||||
}
|
||||
if (settings.previewCodeHighlight)
|
||||
{
|
||||
editormd.loadScript(loadPath + "prettify.min", function() {
|
||||
editormd.loadCSS(loadPath + "highlight/styles/" + settings.highlightStyle);
|
||||
editormd.loadScript(loadPath + "highlight/highlight", function() {
|
||||
loadFlowChartOrSequenceDiagram();
|
||||
});
|
||||
}
|
||||
|
@ -1473,12 +1477,15 @@
|
|||
|
||||
if (settings.previewCodeHighlight)
|
||||
{
|
||||
previewContainer.find("pre").addClass("prettyprint linenums");
|
||||
|
||||
if (typeof prettyPrint !== "undefined")
|
||||
{
|
||||
prettyPrint();
|
||||
}
|
||||
// previewContainer.find("pre").addClass("prettyprint");
|
||||
//
|
||||
// if (typeof prettyPrint !== "undefined")
|
||||
// {
|
||||
// prettyPrint();
|
||||
// }
|
||||
previewContainer.find("pre").each(function (i, block) {
|
||||
hljs.highlightBlock(block);
|
||||
});
|
||||
}
|
||||
|
||||
return this;
|
||||
|
@ -3994,7 +4001,7 @@
|
|||
|
||||
if (settings.previewCodeHighlight)
|
||||
{
|
||||
div.find("pre").addClass("prettyprint linenums");
|
||||
div.find("pre").addClass("prettyprint");
|
||||
prettyPrint();
|
||||
}
|
||||
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 343 B |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue