diff --git a/commands/command.go b/commands/command.go index 379e72a6..d7058ee5 100644 --- a/commands/command.go +++ b/commands/command.go @@ -18,25 +18,32 @@ import ( // RegisterDataBase 注册数据库 func RegisterDataBase() { - host := beego.AppConfig.String("db_host") - database := beego.AppConfig.String("db_database") - username := beego.AppConfig.String("db_username") - password := beego.AppConfig.String("db_password") - timezone := beego.AppConfig.String("timezone") + adapter := beego.AppConfig.String("db_adapter") - port := beego.AppConfig.String("db_port") + if adapter == "mysql" { + host := beego.AppConfig.String("db_host") + database := beego.AppConfig.String("db_database") + username := beego.AppConfig.String("db_username") + password := beego.AppConfig.String("db_password") + timezone := beego.AppConfig.String("timezone") - dataSource := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=true&loc=%s", username, password, host, port, database, url.QueryEscape(timezone)) + port := beego.AppConfig.String("db_port") - orm.RegisterDataBase("default", "mysql", dataSource) + dataSource := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=true&loc=%s", username, password, host, port, database, url.QueryEscape(timezone)) - location, err := time.LoadLocation(timezone) - if err == nil { - orm.DefaultTimeLoc = location - } else { - fmt.Println(err) + orm.RegisterDataBase("default", "mysql", dataSource) + + location, err := time.LoadLocation(timezone) + if err == nil { + orm.DefaultTimeLoc = location + } else { + fmt.Println(err) + } + }else if adapter == "sqlite3" { + database := beego.AppConfig.String("db_database") + + orm.RegisterDataBase("default", "sqlite3", database) } - } // RegisterModel 注册Model diff --git a/commands/install.go b/commands/install.go index ba4125ae..f9241500 100644 --- a/commands/install.go +++ b/commands/install.go @@ -32,25 +32,26 @@ func initialization() { o := orm.NewOrm() - _, err := o.Raw(`INSERT INTO md_options (option_title, option_name, option_value) SELECT '是否启用注册','ENABLED_REGISTER','false' FROM dual WHERE NOT exists(SELECT * FROM md_options WHERE option_name = 'ENABLED_REGISTER');`).Exec() + + _, err := o.Raw(`INSERT INTO md_options (option_title, option_name, option_value) SELECT '是否启用注册','ENABLED_REGISTER','false' WHERE NOT exists(SELECT * FROM md_options WHERE option_name = 'ENABLED_REGISTER');`).Exec() if err != nil { panic("ENABLED_REGISTER => " + err.Error()) os.Exit(1) } - _, err = o.Raw(`INSERT INTO md_options (option_title, option_name, option_value) SELECT '是否启用验证码','ENABLED_CAPTCHA','false' FROM dual WHERE NOT exists(SELECT * FROM md_options WHERE option_name = 'ENABLED_CAPTCHA');`).Exec() + _, err = o.Raw(`INSERT INTO md_options (option_title, option_name, option_value) SELECT '是否启用验证码','ENABLED_CAPTCHA','false' WHERE NOT exists(SELECT * FROM md_options WHERE option_name = 'ENABLED_CAPTCHA');`).Exec() if err != nil { panic("ENABLED_CAPTCHA => " + err.Error()) os.Exit(1) } - _, err = o.Raw(`INSERT INTO md_options (option_title, option_name, option_value) SELECT '启用匿名访问','ENABLE_ANONYMOUS','true' FROM dual WHERE NOT exists(SELECT * FROM md_options WHERE option_name = 'ENABLE_ANONYMOUS');`).Exec() + _, err = o.Raw(`INSERT INTO md_options (option_title, option_name, option_value) SELECT '启用匿名访问','ENABLE_ANONYMOUS','true' WHERE NOT exists(SELECT * FROM md_options WHERE option_name = 'ENABLE_ANONYMOUS');`).Exec() if err != nil { panic("ENABLE_ANONYMOUS => " + err.Error()) os.Exit(1) } - _, err = o.Raw(`INSERT INTO md_options (option_title, option_name, option_value) SELECT '站点名称','SITE_NAME','MinDoc' FROM dual WHERE NOT exists(SELECT * FROM md_options WHERE option_name = 'SITE_NAME');`).Exec() + _, err = o.Raw(`INSERT INTO md_options (option_title, option_name, option_value) SELECT '站点名称','SITE_NAME','MinDoc' WHERE NOT exists(SELECT * FROM md_options WHERE option_name = 'SITE_NAME');`).Exec() if err != nil { panic("SITE_NAME => " + err.Error()) diff --git a/conf/app.conf.example b/conf/app.conf.example index d7643149..e73fc030 100644 --- a/conf/app.conf.example +++ b/conf/app.conf.example @@ -25,7 +25,9 @@ sessionproviderconfig=./logs #时区设置 timezone = Asia/Shanghai -#数据库配置 +####################数据库配置########################### +#支持MySQL和sqlite3两种数据库,如果是sqlite3 则 db_database 标识数据库的物理目录 +db_adapter=mysql|sqlite3 db_host=127.0.0.1 db_port=3306 db_database=mindoc_db diff --git a/main.go b/main.go index 2aaa87bb..c3a2cca3 100644 --- a/main.go +++ b/main.go @@ -13,6 +13,7 @@ import ( "github.com/lifei6671/godoc/conf" "github.com/lifei6671/godoc/controllers" _ "github.com/lifei6671/godoc/routers" + _ "github.com/mattn/go-sqlite3" ) func main() { diff --git a/models/document_search_result.go b/models/document_search_result.go index 6aea442a..bfc34cfa 100644 --- a/models/document_search_result.go +++ b/models/document_search_result.go @@ -38,7 +38,7 @@ WHERE book.privately_owned = 0 AND (doc.document_name LIKE ? OR doc.release LIKE sql2 := `SELECT doc.document_id,doc.modify_time,doc.create_time,doc.document_name,doc.identify,doc.release as description,doc.modify_time,book.identify as book_identify,book.book_name,rel.member_id,member.account AS author FROM md_documents AS doc LEFT JOIN md_books as book ON doc.book_id = book.book_id - LEFT JOIN md_relationship AS rel ON book.book_id = rel.book_id AND role_id = 0 + LEFT JOIN md_relationship AS rel ON book.book_id = rel.book_id AND rel.role_id = 0 LEFT JOIN md_members as member ON rel.member_id = member.member_id WHERE book.privately_owned = 0 AND (doc.document_name LIKE ? OR doc.release LIKE ?) ORDER BY doc.document_id DESC LIMIT ?,? ` @@ -54,13 +54,13 @@ WHERE book.privately_owned = 0 AND (doc.document_name LIKE ? OR doc.release LIKE } else { sql1 := `SELECT count(doc.document_id) as total_count FROM md_documents AS doc LEFT JOIN md_books as book ON doc.book_id = book.book_id - LEFT JOIN md_relationship AS rel ON doc.book_id = rel.book_id AND role_id = 0 + LEFT JOIN md_relationship AS rel ON doc.book_id = rel.book_id AND rel.role_id = 0 LEFT JOIN md_relationship AS rel1 ON doc.book_id = rel1.book_id AND rel1.member_id = ? WHERE (book.privately_owned = 0 OR rel1.relationship_id > 0) AND (doc.document_name LIKE ? OR doc.release LIKE ?) ` sql2 := `SELECT doc.document_id,doc.modify_time,doc.create_time,doc.document_name,doc.identify,doc.release as description,doc.modify_time,book.identify as book_identify,book.book_name,rel.member_id,member.account AS author FROM md_documents AS doc LEFT JOIN md_books as book ON doc.book_id = book.book_id - LEFT JOIN md_relationship AS rel ON book.book_id = rel.book_id AND role_id = 0 + LEFT JOIN md_relationship AS rel ON book.book_id = rel.book_id AND rel.role_id = 0 LEFT JOIN md_members as member ON rel.member_id = member.member_id LEFT JOIN md_relationship AS rel1 ON doc.book_id = rel1.book_id AND rel1.member_id = ? WHERE (book.privately_owned = 0 OR rel1.relationship_id > 0) AND (doc.document_name LIKE ? OR doc.release LIKE ?) diff --git a/static/css/kancloud.css b/static/css/kancloud.css index b937bd88..83afe452 100644 --- a/static/css/kancloud.css +++ b/static/css/kancloud.css @@ -360,6 +360,10 @@ h6 { background: linear-gradient(to bottom, #10af88 0%, #10af88 100%); color: #ffffff; } +.m-manual .markdown-body .search-highlight{ + background-color: #FFFF00 !important; + font-style: normal; +} .m-manual .manual-left .m-copyright { border-top: 0; background: #fafafa; diff --git a/views/document/default_read.tpl b/views/document/default_read.tpl index a1613f90..48bdd273 100644 --- a/views/document/default_read.tpl +++ b/views/document/default_read.tpl @@ -108,7 +108,7 @@ @@ -236,7 +236,7 @@ hljs.initLineNumbersOnLoad(); } - function loadDocument($url,$id) { + function loadDocument($url,$id,$callback) { $.ajax({ url : $url, type : "GET", @@ -247,6 +247,9 @@ if(body && title && doc_title){ + if (typeof $callback === "function") { + body = $callback(body); + } $("#page-content").html(body); $("title").text(title); $("#article-title").text(doc_title); @@ -263,7 +266,11 @@ var doc_title = res.data.doc_title; var title = res.data.title; - $("#page-content").html(body); + $body = body; + if (typeof $callback === "function" ){ + $body = $callback(body); + } + $("#page-content").html($body); $("title").text(title); $("#article-title").text(doc_title); @@ -285,7 +292,6 @@ $(function () { $(".view-backtop").on("click", function () { - console.log("a") $('.manual-right').animate({ scrollTop: '0px' }, 200); }); $(".manual-right").scroll(function () { @@ -373,6 +379,7 @@ return false; } $("#btnSearch").attr("disabled","disabled").find("i").removeClass("fa-search").addClass("loading"); + window.keyword = keyword; }, success :function (res) { var html = ""; @@ -399,7 +406,14 @@ var url = "{{urlfor "DocumentController.Read" ":key" .Model.Identify ":id" ""}}/" + id; $(this).parent("li").siblings().find("a").removeClass("active"); $(this).addClass("active"); - loadDocument(url,id); + loadDocument(url,id,function (body) { + if(body !== ""){ + console.log(window.keyword); + + body = body.replace(new RegExp(window.keyword,"g"),'' + window.keyword + ''); + } + return body; + }); }); }); diff --git a/views/widgets/header.tpl b/views/widgets/header.tpl index 39d8bb7c..20be001b 100644 --- a/views/widgets/header.tpl +++ b/views/widgets/header.tpl @@ -21,16 +21,6 @@