Skip to content

Commit

Permalink
宽屏模式
Browse files Browse the repository at this point in the history
  • Loading branch information
movsb committed Apr 8, 2024
1 parent cdc9e20 commit 1741bb6
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 6 deletions.
4 changes: 1 addition & 3 deletions theme/blog/statics/scripts/footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,7 @@ class __Vim {
}
},
w: function() {
let elem = document.getElementById('content');
let maxWidth = elem.style.maxWidth;
elem.style.maxWidth = maxWidth == 'unset' ? 'var(--max-width)' : 'unset';
document.body.classList.toggle("wide");
},
r: function() {
location.reload();
Expand Down
6 changes: 5 additions & 1 deletion theme/blog/styles/content.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
/* 内容 */

#content {
max-width: var(--max-width);
max-width: var(--max-width);
}

body.wide #content {
max-width: unset;
}

#content {
Expand Down
2 changes: 1 addition & 1 deletion theme/blog/styles/global.scss
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ table {

td, th {
border: var(--table-border);
padding: 0.4em 0.8em;
padding: 0.2em 0.8em;
}

&.no-border, &.no-border td {
Expand Down
2 changes: 1 addition & 1 deletion theme/blog/templates/_header.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<script src="/scripts/header.js"></script>
{{ render "custom_header" . }}
</head>
<body class="line-numbers">
<body class="{{ $.BodyClass }}">
<div id="wrapper">
<!-- 头部开始 -->
{{ if not .Post }}
Expand Down
13 changes: 13 additions & 0 deletions theme/data/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package data
import (
"html/template"
"io"
"strings"

"github.com/movsb/taoblog/config"
"github.com/movsb/taoblog/modules/auth"
Expand Down Expand Up @@ -49,6 +50,18 @@ type Data struct {
Tag *TagData
}

func (d *Data) BodyClass() string {
c := []string{
`line-numbers`,
}
if d.Post != nil {
if d.Post.Post.Wide() {
c = append(c, `wide`)
}
}
return strings.Join(c, ` `)
}

func (d *Data) Author() string {
if d.Config.Comment.Author != `` {
return d.Config.Comment.Author
Expand Down
8 changes: 8 additions & 0 deletions theme/data/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,11 @@ func (p *Post) Outdated() bool {
}
return false
}

// 是否开启宽屏?
func (p *Post) Wide() bool {
if value, ok := p.Metas[`wide`]; ok && (value == `true` || value == `1`) {
return true
}
return false
}

0 comments on commit 1741bb6

Please sign in to comment.