Skip to content

Commit ab4027e

Browse files
committed
支持夜间模式
1 parent 5892ba1 commit ab4027e

File tree

3 files changed

+83
-19
lines changed

3 files changed

+83
-19
lines changed

controllers/DocumentController.go

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ var (
5454
`
5555
)
5656

57-
//DocumentController struct.
57+
// DocumentController struct.
5858
type DocumentController struct {
5959
BaseController
6060
}
@@ -93,7 +93,7 @@ func parseGitCommit(str string) (cont, commit string) {
9393
return
9494
}
9595

96-
//判断用户是否可以阅读文档.
96+
// 判断用户是否可以阅读文档.
9797
func isReadable(identify, token string, this *DocumentController) *models.BookResult {
9898
book, err := models.NewBook().FindByFieldFirst("identify", identify)
9999
if err != nil {
@@ -153,7 +153,7 @@ func isReadable(identify, token string, this *DocumentController) *models.BookRe
153153
return bookResult
154154
}
155155

156-
//文档首页.
156+
// 文档首页.
157157
func (this *DocumentController) Index() {
158158
identify := this.Ctx.Input.Param(":key")
159159
if identify == "" {
@@ -210,7 +210,7 @@ func (this *DocumentController) Index() {
210210
this.Data["RelateBooks"] = models.NewRelateBook().Lists(bookResult.BookId)
211211
}
212212

213-
//文档首页.
213+
// 文档首页.
214214
func (this *DocumentController) indexWithPassword() {
215215
identify := this.Ctx.Input.Param(":key")
216216
if identify == "" {
@@ -226,7 +226,7 @@ func (this *DocumentController) indexWithPassword() {
226226
this.Data["Identify"] = identify
227227
}
228228

229-
//阅读文档.
229+
// 阅读文档.
230230
func (this *DocumentController) Read() {
231231

232232
identify := this.Ctx.Input.Param(":key")
@@ -477,6 +477,7 @@ func (this *DocumentController) Read() {
477477
if wd := this.GetString("wd"); strings.TrimSpace(wd) != "" {
478478
this.Data["Keywords"] = models.NewElasticSearchClient().SegWords(wd)
479479
}
480+
this.Data["IsThemeDark"] = this.Ctx.GetCookie("theme-dark") == "true"
480481
this.Data["Bookmark"] = existBookmark
481482
this.Data["Model"] = bookResult
482483
this.Data["Book"] = bookResult //文档下载需要用到Book变量
@@ -492,7 +493,7 @@ func (this *DocumentController) Read() {
492493
this.Data["Percent"] = percent
493494
}
494495

495-
//编辑文档.
496+
// 编辑文档.
496497
func (this *DocumentController) Edit() {
497498
docId := 0 // 文档id
498499

@@ -563,7 +564,7 @@ func (this *DocumentController) Edit() {
563564
}
564565
}
565566

566-
//创建一个文档.
567+
// 创建一个文档.
567568
func (this *DocumentController) Create() {
568569
identify := this.GetString("identify") //书籍书籍标识
569570
docIdentify := this.GetString("doc_identify") //新建的文档标识
@@ -663,7 +664,7 @@ func (this *DocumentController) Create() {
663664
this.JsonResult(0, "ok", document)
664665
}
665666

666-
//批量创建文档
667+
// 批量创建文档
667668
func (this *DocumentController) CreateMulti() {
668669
bookId, _ := this.GetInt("book_id")
669670

@@ -708,7 +709,7 @@ func (this *DocumentController) CreateMulti() {
708709
this.JsonResult(0, "添加成功")
709710
}
710711

711-
//上传附件或图片.
712+
// 上传附件或图片.
712713
func (this *DocumentController) Upload() {
713714
identify := this.GetString("identify")
714715
docId, _ := this.GetInt("doc_id")
@@ -866,7 +867,7 @@ func (this *DocumentController) Upload() {
866867
this.StopRun()
867868
}
868869

869-
//DownloadAttachment 下载附件.
870+
// DownloadAttachment 下载附件.
870871
func (this *DocumentController) DownloadAttachment() {
871872
identify := this.Ctx.Input.Param(":key")
872873
attachId, _ := strconv.Atoi(this.Ctx.Input.Param(":attach_id"))
@@ -919,7 +920,7 @@ func (this *DocumentController) DownloadAttachment() {
919920
this.StopRun()
920921
}
921922

922-
//删除附件.
923+
// 删除附件.
923924
func (this *DocumentController) RemoveAttachment() {
924925
attachId, _ := this.GetInt("attach_id")
925926
if attachId <= 0 {
@@ -958,7 +959,7 @@ func (this *DocumentController) RemoveAttachment() {
958959
this.JsonResult(0, "ok", attach)
959960
}
960961

961-
//删除文档.
962+
// 删除文档.
962963
func (this *DocumentController) Delete() {
963964

964965
identify := this.GetString("identify")
@@ -1222,7 +1223,7 @@ func (this *DocumentController) Content() {
12221223

12231224
}
12241225

1225-
//导出文件
1226+
// 导出文件
12261227
func (this *DocumentController) ExportOld() {
12271228
wecode := strings.TrimSpace(this.GetString("wecode"))
12281229
if wecode == "" && (this.Member == nil || this.Member.MemberId == 0) {
@@ -1286,7 +1287,7 @@ func (this *DocumentController) ExportOld() {
12861287
this.JsonResult(1, "下载失败,您要下载的书籍当前并未生成可下载的电子书。")
12871288
}
12881289

1289-
//导出文件
1290+
// 导出文件
12901291
func (this *DocumentController) Export() {
12911292
wecode := strings.TrimSpace(this.GetString("wecode"))
12921293
if wecode == "" && (this.Member == nil || this.Member.MemberId == 0) {
@@ -1389,7 +1390,7 @@ func (this *DocumentController) QrCode() {
13891390
}
13901391
}
13911392

1392-
//书籍内搜索.
1393+
// 书籍内搜索.
13931394
func (this *DocumentController) Search() {
13941395
identify := this.Ctx.Input.Param(":key")
13951396
token := this.GetString("token")
@@ -1443,7 +1444,7 @@ func (this *DocumentController) Search() {
14431444
}
14441445
}
14451446

1446-
//文档历史列表.
1447+
// 文档历史列表.
14471448
func (this *DocumentController) History() {
14481449

14491450
this.TplName = "document/history.html"
@@ -1667,7 +1668,7 @@ func (this *DocumentController) Compare() {
16671668
this.Data["Content"] = ModelStore.GetFiledById(doc.DocumentId, "markdown")
16681669
}
16691670

1670-
//递归生成文档序列数组.
1671+
// 递归生成文档序列数组.
16711672
func RecursiveFun(parentId int, prefix, dpath string, this *DocumentController, book *models.BookResult, docs []*models.Document, paths *list.List) {
16721673
for _, item := range docs {
16731674
if item.ParentId == parentId {

static/css/bookstack.css

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1548,4 +1548,46 @@ form .btn-row .col-md-10{padding-left: 0;}
15481548
.locked-reading .locked-icon{
15491549
width: 128px;height: 128px;margin: 100px auto 15px;
15501550
background: url("/static/images/lock.png") no-repeat center center;
1551-
}
1551+
}
1552+
1553+
html.theme-dark{
1554+
filter: invert(1) hue-rotate(180deg);
1555+
}
1556+
1557+
html.theme-dark img{
1558+
filter: invert(1) hue-rotate(180deg);
1559+
}
1560+
1561+
html.theme-dark .bookstack-item img{
1562+
filter: none;
1563+
}
1564+
1565+
html.theme-dark body{
1566+
font-family: PingFang SC,-apple-system,SF UI Text,Lucida Grande,STheiti,Microsoft YaHei,sans-serif;
1567+
}
1568+
1569+
html.theme-dark .markdown-body{
1570+
color: #666;
1571+
font-family: unset;
1572+
}
1573+
1574+
html.theme-dark .editormd-preview-container code,html.theme-dark .editormd-html-preview code{
1575+
background-color: #ccc;
1576+
}
1577+
1578+
html.theme-dark .editormd-preview-container blockquote,html.theme-dark .editormd-html-preview blockquote{
1579+
border-color: #aaa;
1580+
background-color: #ddd;
1581+
}
1582+
1583+
html.theme-dark .editormd-preview-container pre,html.theme-dark .editormd-html-preview pre{
1584+
background-color: #ccc;
1585+
}
1586+
1587+
html.theme-dark .com{
1588+
color: #888;
1589+
}
1590+
html span.moon{display: inline-block;}
1591+
html.theme-dark span.moon{display: none;}
1592+
html span.sun{display: none;}
1593+
html.theme-dark span.sun{display: inline-block;}

views/document/default_read.html

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!DOCTYPE html>
2-
<html lang="zh-CN">
2+
<html lang="zh-CN" {{if $.IsThemeDark}}class="theme-dark"{{end}}>
33
<head>
44
<meta charset="utf-8">
55
<meta http-equiv="X-UA-Compatible" content="IE=edge">
@@ -49,6 +49,11 @@
4949
{{.Name}}</a>
5050
{{end}}
5151

52+
<a href="javascript:;" class="btn btn-link btn-theme">
53+
<span class="tooltips sun" title="切换白天浅色模式" data-placement="bottom"><i class="fa fa-sun-o"></i> 白天</span>
54+
<span class="tooltips moon" title="切换夜间深色模式" data-placement="bottom"><i class="fa fa-moon-o"></i> 夜间</span>
55+
</a>
56+
5257
{{if $.Wxacode}}
5358
<a title="下载" href="javascript:" data-toggle="modal" data-target="#ModalBookChat" class="btn btn-light">
5459
<img src="/static/images/wxacode.png" style="position: relative;top:-2px;" alt="BookChat 小程序"> <span>小程序</span></a>
@@ -420,6 +425,22 @@ <h1 class="modal-title" id="ModalReplaceLabel" style="align:center;">思维导
420425
$(this).parent().addClass("collapse-hide")
421426
}
422427
})
428+
429+
$(".btn-theme").click(function(){
430+
if($("html").hasClass("theme-dark")){
431+
$("html").removeClass("theme-dark")
432+
setCookie('theme-dark',false,-1000)
433+
}else{
434+
$("html").addClass("theme-dark")
435+
setCookie('theme-dark',true,3600*24*365*1000)
436+
}
437+
})
438+
439+
function setCookie(name, value, time){
440+
var exp = new Date();
441+
exp.setTime(exp.getTime() + time);
442+
document.cookie = name + "="+ escape (value) + ";path=/;expires=" + exp.toGMTString();
443+
}
423444
});
424445
</script>
425446
</body>

0 commit comments

Comments
 (0)