mirror of https://github.com/mindoc-org/mindoc.git
parent
fc9678b414
commit
79a464352e
|
@ -18,25 +18,32 @@ import (
|
||||||
|
|
||||||
// RegisterDataBase 注册数据库
|
// RegisterDataBase 注册数据库
|
||||||
func RegisterDataBase() {
|
func RegisterDataBase() {
|
||||||
host := beego.AppConfig.String("db_host")
|
adapter := beego.AppConfig.String("db_adapter")
|
||||||
database := beego.AppConfig.String("db_database")
|
|
||||||
username := beego.AppConfig.String("db_username")
|
|
||||||
password := beego.AppConfig.String("db_password")
|
|
||||||
timezone := beego.AppConfig.String("timezone")
|
|
||||||
|
|
||||||
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)
|
orm.RegisterDataBase("default", "mysql", dataSource)
|
||||||
if err == nil {
|
|
||||||
orm.DefaultTimeLoc = location
|
location, err := time.LoadLocation(timezone)
|
||||||
} else {
|
if err == nil {
|
||||||
fmt.Println(err)
|
orm.DefaultTimeLoc = location
|
||||||
|
} else {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
}else if adapter == "sqlite3" {
|
||||||
|
database := beego.AppConfig.String("db_database")
|
||||||
|
|
||||||
|
orm.RegisterDataBase("default", "sqlite3", database)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterModel 注册Model
|
// RegisterModel 注册Model
|
||||||
|
|
|
@ -32,25 +32,26 @@ func initialization() {
|
||||||
|
|
||||||
o := orm.NewOrm()
|
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 {
|
if err != nil {
|
||||||
panic("ENABLED_REGISTER => " + err.Error())
|
panic("ENABLED_REGISTER => " + err.Error())
|
||||||
os.Exit(1)
|
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 {
|
if err != nil {
|
||||||
panic("ENABLED_CAPTCHA => " + err.Error())
|
panic("ENABLED_CAPTCHA => " + err.Error())
|
||||||
os.Exit(1)
|
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 {
|
if err != nil {
|
||||||
panic("ENABLE_ANONYMOUS => " + err.Error())
|
panic("ENABLE_ANONYMOUS => " + err.Error())
|
||||||
os.Exit(1)
|
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 {
|
if err != nil {
|
||||||
panic("SITE_NAME => " + err.Error())
|
panic("SITE_NAME => " + err.Error())
|
||||||
|
|
|
@ -25,7 +25,9 @@ sessionproviderconfig=./logs
|
||||||
#时区设置
|
#时区设置
|
||||||
timezone = Asia/Shanghai
|
timezone = Asia/Shanghai
|
||||||
|
|
||||||
#数据库配置
|
####################数据库配置###########################
|
||||||
|
#支持MySQL和sqlite3两种数据库,如果是sqlite3 则 db_database 标识数据库的物理目录
|
||||||
|
db_adapter=mysql|sqlite3
|
||||||
db_host=127.0.0.1
|
db_host=127.0.0.1
|
||||||
db_port=3306
|
db_port=3306
|
||||||
db_database=mindoc_db
|
db_database=mindoc_db
|
||||||
|
|
1
main.go
1
main.go
|
@ -13,6 +13,7 @@ import (
|
||||||
"github.com/lifei6671/godoc/conf"
|
"github.com/lifei6671/godoc/conf"
|
||||||
"github.com/lifei6671/godoc/controllers"
|
"github.com/lifei6671/godoc/controllers"
|
||||||
_ "github.com/lifei6671/godoc/routers"
|
_ "github.com/lifei6671/godoc/routers"
|
||||||
|
_ "github.com/mattn/go-sqlite3"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
@ -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
|
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_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_members as member ON rel.member_id = member.member_id
|
||||||
WHERE book.privately_owned = 0 AND (doc.document_name LIKE ? OR doc.release LIKE ?)
|
WHERE book.privately_owned = 0 AND (doc.document_name LIKE ? OR doc.release LIKE ?)
|
||||||
ORDER BY doc.document_id DESC LIMIT ?,? `
|
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 {
|
} else {
|
||||||
sql1 := `SELECT count(doc.document_id) as total_count FROM md_documents AS doc
|
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_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 = ?
|
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 ?) `
|
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
|
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_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_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 = ?
|
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 ?)
|
WHERE (book.privately_owned = 0 OR rel1.relationship_id > 0) AND (doc.document_name LIKE ? OR doc.release LIKE ?)
|
||||||
|
|
|
@ -360,6 +360,10 @@ h6 {
|
||||||
background: linear-gradient(to bottom, #10af88 0%, #10af88 100%);
|
background: linear-gradient(to bottom, #10af88 0%, #10af88 100%);
|
||||||
color: #ffffff;
|
color: #ffffff;
|
||||||
}
|
}
|
||||||
|
.m-manual .markdown-body .search-highlight{
|
||||||
|
background-color: #FFFF00 !important;
|
||||||
|
font-style: normal;
|
||||||
|
}
|
||||||
.m-manual .manual-left .m-copyright {
|
.m-manual .manual-left .m-copyright {
|
||||||
border-top: 0;
|
border-top: 0;
|
||||||
background: #fafafa;
|
background: #fafafa;
|
||||||
|
|
|
@ -108,7 +108,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="m-copyright">
|
<div class="m-copyright">
|
||||||
<p>
|
<p>
|
||||||
本文档使用 <a href="https://doc.iminho.me" target="_blank">MinDoc</a> 发布
|
本文档使用 <a href="https://www.iminho.me" target="_blank">MinDoc</a> 发布
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -236,7 +236,7 @@
|
||||||
|
|
||||||
hljs.initLineNumbersOnLoad();
|
hljs.initLineNumbersOnLoad();
|
||||||
}
|
}
|
||||||
function loadDocument($url,$id) {
|
function loadDocument($url,$id,$callback) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url : $url,
|
url : $url,
|
||||||
type : "GET",
|
type : "GET",
|
||||||
|
@ -247,6 +247,9 @@
|
||||||
|
|
||||||
if(body && title && doc_title){
|
if(body && title && doc_title){
|
||||||
|
|
||||||
|
if (typeof $callback === "function") {
|
||||||
|
body = $callback(body);
|
||||||
|
}
|
||||||
$("#page-content").html(body);
|
$("#page-content").html(body);
|
||||||
$("title").text(title);
|
$("title").text(title);
|
||||||
$("#article-title").text(doc_title);
|
$("#article-title").text(doc_title);
|
||||||
|
@ -263,7 +266,11 @@
|
||||||
var doc_title = res.data.doc_title;
|
var doc_title = res.data.doc_title;
|
||||||
var title = res.data.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);
|
$("title").text(title);
|
||||||
$("#article-title").text(doc_title);
|
$("#article-title").text(doc_title);
|
||||||
|
|
||||||
|
@ -285,7 +292,6 @@
|
||||||
|
|
||||||
$(function () {
|
$(function () {
|
||||||
$(".view-backtop").on("click", function () {
|
$(".view-backtop").on("click", function () {
|
||||||
console.log("a")
|
|
||||||
$('.manual-right').animate({ scrollTop: '0px' }, 200);
|
$('.manual-right').animate({ scrollTop: '0px' }, 200);
|
||||||
});
|
});
|
||||||
$(".manual-right").scroll(function () {
|
$(".manual-right").scroll(function () {
|
||||||
|
@ -373,6 +379,7 @@
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$("#btnSearch").attr("disabled","disabled").find("i").removeClass("fa-search").addClass("loading");
|
$("#btnSearch").attr("disabled","disabled").find("i").removeClass("fa-search").addClass("loading");
|
||||||
|
window.keyword = keyword;
|
||||||
},
|
},
|
||||||
success :function (res) {
|
success :function (res) {
|
||||||
var html = "";
|
var html = "";
|
||||||
|
@ -399,7 +406,14 @@
|
||||||
var url = "{{urlfor "DocumentController.Read" ":key" .Model.Identify ":id" ""}}/" + id;
|
var url = "{{urlfor "DocumentController.Read" ":key" .Model.Identify ":id" ""}}/" + id;
|
||||||
$(this).parent("li").siblings().find("a").removeClass("active");
|
$(this).parent("li").siblings().find("a").removeClass("active");
|
||||||
$(this).addClass("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>
|
</script>
|
||||||
|
|
|
@ -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>
|
<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">
|
<ul class="dropdown-menu" role="menu">
|
||||||
{{if gt .Member.MemberId 0}}
|
{{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>
|
<li>
|
||||||
<a href="{{urlfor "SettingController.Index"}}" title="个人中心"><i class="fa fa-user" aria-hidden="true"></i> 个人中心</a>
|
<a href="{{urlfor "SettingController.Index"}}" title="个人中心"><i class="fa fa-user" aria-hidden="true"></i> 个人中心</a>
|
||||||
</li>
|
</li>
|
||||||
|
@ -45,8 +35,7 @@
|
||||||
<li>
|
<li>
|
||||||
<a href="{{urlfor "AccountController.Logout"}}" title="退出登录"><i class="fa fa-sign-out"></i> 退出登录</a>
|
<a href="{{urlfor "AccountController.Logout"}}" title="退出登录"><i class="fa fa-sign-out"></i> 退出登录</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
|
||||||
</li>
|
|
||||||
{{else}}
|
{{else}}
|
||||||
<li><a href="{{urlfor "AccountController.Login"}}" title="用户登录">登录</a></li>
|
<li><a href="{{urlfor "AccountController.Login"}}" title="用户登录">登录</a></li>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
Loading…
Reference in New Issue