diff --git a/theme/blog/statics/scripts/footer.js b/theme/blog/statics/scripts/footer.js index 1c4b1788..73c4aa50 100644 --- a/theme/blog/statics/scripts/footer.js +++ b/theme/blog/statics/scripts/footer.js @@ -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(); diff --git a/theme/blog/styles/content.scss b/theme/blog/styles/content.scss index f6600157..51e6f42e 100644 --- a/theme/blog/styles/content.scss +++ b/theme/blog/styles/content.scss @@ -1,7 +1,11 @@ /* 内容 */ #content { - max-width: var(--max-width); + max-width: var(--max-width); +} + +body.wide #content { + max-width: unset; } #content { diff --git a/theme/blog/styles/global.scss b/theme/blog/styles/global.scss index 81dff666..53418aea 100644 --- a/theme/blog/styles/global.scss +++ b/theme/blog/styles/global.scss @@ -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 { diff --git a/theme/blog/templates/_header.html b/theme/blog/templates/_header.html index 874aedd3..3347290a 100644 --- a/theme/blog/templates/_header.html +++ b/theme/blog/templates/_header.html @@ -17,7 +17,7 @@ {{ render "custom_header" . }} - +
{{ if not .Post }} diff --git a/theme/data/data.go b/theme/data/data.go index 969ee708..2433952b 100644 --- a/theme/data/data.go +++ b/theme/data/data.go @@ -3,6 +3,7 @@ package data import ( "html/template" "io" + "strings" "github.com/movsb/taoblog/config" "github.com/movsb/taoblog/modules/auth" @@ -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 diff --git a/theme/data/post.go b/theme/data/post.go index 25d0051c..6cae1339 100644 --- a/theme/data/post.go +++ b/theme/data/post.go @@ -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 +}