1、支持sqlite3数据库

2、高亮阅读模式下搜索关键字
pull/39/head
Minho 2017-05-20 09:52:18 +08:00
parent fc9678b414
commit 79a464352e
8 changed files with 57 additions and 39 deletions

View File

@ -18,6 +18,9 @@ import (
// RegisterDataBase 注册数据库
func RegisterDataBase() {
adapter := beego.AppConfig.String("db_adapter")
if adapter == "mysql" {
host := beego.AppConfig.String("db_host")
database := beego.AppConfig.String("db_database")
username := beego.AppConfig.String("db_username")
@ -36,7 +39,11 @@ func RegisterDataBase() {
} else {
fmt.Println(err)
}
}else if adapter == "sqlite3" {
database := beego.AppConfig.String("db_database")
orm.RegisterDataBase("default", "sqlite3", database)
}
}
// RegisterModel 注册Model

View File

@ -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())

View File

@ -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

View File

@ -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() {

View File

@ -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 ?)

View File

@ -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;

View File

@ -108,7 +108,7 @@
</div>
<div class="m-copyright">
<p>
本文档使用 <a href="https://doc.iminho.me" target="_blank">MinDoc</a> 发布
本文档使用 <a href="https://www.iminho.me" target="_blank">MinDoc</a> 发布
</p>
</div>
</div>
@ -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"),'<em class="search-highlight">' + window.keyword + '</em>');
}
return body;
});
});
});
</script>

View File

@ -21,16 +21,6 @@
<button class="btn btn-default dropdown-toggle hidden-lg" type="button" data-toggle="dropdown"><i class="fa fa-align-justify"></i></button>
<ul class="dropdown-menu" role="menu">
{{if gt .Member.MemberId 0}}
<li>
<div class="img user-info" data-toggle="dropdown">
<img src="{{cdnimg .Member.Avatar}}" class="img-circle userbar-avatar" alt="{{.Member.Account}}">
<div class="userbar-content">
<span>{{.Member.Account}}</span>
<div>{{.Member.RoleName}}</div>
</div>
<i class="fa fa-chevron-down" aria-hidden="true"></i>
</div>
<ul class="dropdown-menu user-info-dropdown" role="menu">
<li>
<a href="{{urlfor "SettingController.Index"}}" title="个人中心"><i class="fa fa-user" aria-hidden="true"></i> 个人中心</a>
</li>
@ -45,8 +35,7 @@
<li>
<a href="{{urlfor "AccountController.Logout"}}" title="退出登录"><i class="fa fa-sign-out"></i> 退出登录</a>
</li>
</ul>
</li>
{{else}}
<li><a href="{{urlfor "AccountController.Login"}}" title="用户登录">登录</a></li>
{{end}}