custom-header fifteen页眉图片设置
This commit is contained in:
parent
f722d685ea
commit
1d80534333
|
@ -11,7 +11,6 @@ import (
|
||||||
"github.com/fthvgb1/wp-go/internal/pkg/logs"
|
"github.com/fthvgb1/wp-go/internal/pkg/logs"
|
||||||
"github.com/fthvgb1/wp-go/internal/plugins"
|
"github.com/fthvgb1/wp-go/internal/plugins"
|
||||||
"github.com/fthvgb1/wp-go/internal/theme"
|
"github.com/fthvgb1/wp-go/internal/theme"
|
||||||
"github.com/fthvgb1/wp-go/internal/theme/common"
|
|
||||||
"github.com/fthvgb1/wp-go/internal/wpconfig"
|
"github.com/fthvgb1/wp-go/internal/wpconfig"
|
||||||
"github.com/fthvgb1/wp-go/model"
|
"github.com/fthvgb1/wp-go/model"
|
||||||
"log"
|
"log"
|
||||||
|
@ -107,7 +106,7 @@ func reload() {
|
||||||
logs.ErrPrintln(err, "获取网站设置WpOption失败")
|
logs.ErrPrintln(err, "获取网站设置WpOption失败")
|
||||||
err = wpconfig.InitTerms()
|
err = wpconfig.InitTerms()
|
||||||
wpconfig.FlushModes()
|
wpconfig.FlushModes()
|
||||||
common.Reload()
|
theme.Reload()
|
||||||
logs.ErrPrintln(err, "获取WpTerms表失败")
|
logs.ErrPrintln(err, "获取WpTerms表失败")
|
||||||
if middleWareReloadFn != nil {
|
if middleWareReloadFn != nil {
|
||||||
middleWareReloadFn()
|
middleWareReloadFn()
|
||||||
|
|
33
internal/theme/common/customheader.go
Normal file
33
internal/theme/common/customheader.go
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
package common
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/fthvgb1/wp-go/helper/slice"
|
||||||
|
"github.com/fthvgb1/wp-go/internal/pkg/cache"
|
||||||
|
"github.com/fthvgb1/wp-go/internal/pkg/logs"
|
||||||
|
"github.com/fthvgb1/wp-go/internal/pkg/models"
|
||||||
|
"github.com/fthvgb1/wp-go/internal/wpconfig"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (h *Handle) DisplayHeaderText() bool {
|
||||||
|
mods, err := wpconfig.GetThemeMods(h.Theme)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return mods.ThemeSupport.CustomHeader.HeaderText && "blank" != mods.HeaderTextcolor
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *Handle) GetCustomHeader() (r models.PostThumbnail, isRand bool) {
|
||||||
|
hs, err := cache.GetHeaderImages(h.C, h.Theme)
|
||||||
|
if err != nil {
|
||||||
|
logs.ErrPrintln(err, "获取页眉背景图失败")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(hs) < 1 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(hs) > 1 {
|
||||||
|
isRand = true
|
||||||
|
}
|
||||||
|
r, _ = slice.RandPop(&hs)
|
||||||
|
return
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
package common
|
package common
|
||||||
|
|
||||||
func Reload() {
|
func Reload() {
|
||||||
backgroud.Flush()
|
backgroud.Store("default")
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,11 @@ func InitTheme() {
|
||||||
common.AddThemeSupport(twentyfifteen.ThemeName, twentyfifteen.ThemeSupport())
|
common.AddThemeSupport(twentyfifteen.ThemeName, twentyfifteen.ThemeSupport())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Reload() {
|
||||||
|
twentyfifteen.Reload()
|
||||||
|
common.Reload()
|
||||||
|
}
|
||||||
|
|
||||||
func GetTemplateName() string {
|
func GetTemplateName() string {
|
||||||
tmlp := config.GetConfig().Theme
|
tmlp := config.GetConfig().Theme
|
||||||
if tmlp == "" {
|
if tmlp == "" {
|
||||||
|
|
124
internal/theme/twentyfifteen/customheader.go
Normal file
124
internal/theme/twentyfifteen/customheader.go
Normal file
|
@ -0,0 +1,124 @@
|
||||||
|
package twentyfifteen
|
||||||
|
|
||||||
|
import (
|
||||||
|
str "github.com/fthvgb1/wp-go/helper/strings"
|
||||||
|
"github.com/fthvgb1/wp-go/safety"
|
||||||
|
)
|
||||||
|
|
||||||
|
var style = `<style type="text/css" id="twentyfifteen-header-css">`
|
||||||
|
var defaultTextStyle = `.site-header {
|
||||||
|
padding-top: 14px;
|
||||||
|
padding-bottom: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.site-branding {
|
||||||
|
min-height: 42px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (min-width: 46.25em) {
|
||||||
|
.site-header {
|
||||||
|
padding-top: 21px;
|
||||||
|
padding-bottom: 21px;
|
||||||
|
}
|
||||||
|
.site-branding {
|
||||||
|
min-height: 56px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@media screen and (min-width: 55em) {
|
||||||
|
.site-header {
|
||||||
|
padding-top: 25px;
|
||||||
|
padding-bottom: 25px;
|
||||||
|
}
|
||||||
|
.site-branding {
|
||||||
|
min-height: 62px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@media screen and (min-width: 59.6875em) {
|
||||||
|
.site-header {
|
||||||
|
padding-top: 0;
|
||||||
|
padding-bottom: 0;
|
||||||
|
}
|
||||||
|
.site-branding {
|
||||||
|
min-height: 0;
|
||||||
|
}
|
||||||
|
}`
|
||||||
|
var imgStyle = `.site-header {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* No shorthand so the Customizer can override individual properties.
|
||||||
|
* @see https://core.trac.wordpress.org/ticket/31460
|
||||||
|
*/
|
||||||
|
background-image: url("%s");
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
background-position: 50% 50%;
|
||||||
|
-webkit-background-size: cover;
|
||||||
|
-moz-background-size: cover;
|
||||||
|
-o-background-size: cover;
|
||||||
|
background-size: cover;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (min-width: 59.6875em) {
|
||||||
|
body:before {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* No shorthand so the Customizer can override individual properties.
|
||||||
|
* @see https://core.trac.wordpress.org/ticket/31460
|
||||||
|
*/
|
||||||
|
background-image: url("%s");
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
background-position: 100% 50%;
|
||||||
|
-webkit-background-size: cover;
|
||||||
|
-moz-background-size: cover;
|
||||||
|
-o-background-size: cover;
|
||||||
|
background-size: cover;
|
||||||
|
border-right: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.site-header {
|
||||||
|
background: transparent;
|
||||||
|
}
|
||||||
|
}`
|
||||||
|
|
||||||
|
var header = safety.NewVar("default")
|
||||||
|
|
||||||
|
func Reload() {
|
||||||
|
header.Store("default")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *handle) CalCustomHeader() (r string, rand bool) {
|
||||||
|
img, rand := h.IndexHandle.GetCustomHeader()
|
||||||
|
if img.Path == "" && h.IndexHandle.DisplayHeaderText() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ss := str.NewBuilder()
|
||||||
|
ss.WriteString(style)
|
||||||
|
if img.Path == "" && !h.IndexHandle.DisplayHeaderText() {
|
||||||
|
ss.WriteString(defaultTextStyle)
|
||||||
|
}
|
||||||
|
if img.Path != "" {
|
||||||
|
ss.Sprintf(imgStyle, img.Path, img.Path)
|
||||||
|
}
|
||||||
|
if !h.IndexHandle.DisplayHeaderText() {
|
||||||
|
ss.WriteString(`.site-title,
|
||||||
|
.site-description {
|
||||||
|
clip: rect(1px, 1px, 1px, 1px);
|
||||||
|
position: absolute;
|
||||||
|
}`)
|
||||||
|
}
|
||||||
|
ss.WriteString("</style>")
|
||||||
|
r = ss.String()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *handle) CustomHeader() {
|
||||||
|
headers := header.Load()
|
||||||
|
if headers == "default" {
|
||||||
|
headerss, rand := h.CalCustomHeader()
|
||||||
|
headers = headerss
|
||||||
|
if !rand {
|
||||||
|
header.Store(headers)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
h.IndexHandle.GinH["customHeader"] = headers
|
||||||
|
return
|
||||||
|
}
|
|
@ -61,4 +61,7 @@
|
||||||
{{if .customBackground}}
|
{{if .customBackground}}
|
||||||
{{.customBackground|unescaped}}
|
{{.customBackground|unescaped}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
{{if .customHeader}}
|
||||||
|
{{.customHeader|unescaped}}
|
||||||
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
|
@ -12,12 +12,13 @@ import (
|
||||||
|
|
||||||
const ThemeName = "twentyfifteen"
|
const ThemeName = "twentyfifteen"
|
||||||
|
|
||||||
type indexHandle struct {
|
type handle struct {
|
||||||
*common.IndexHandle
|
*common.IndexHandle
|
||||||
|
*common.DetailHandle
|
||||||
}
|
}
|
||||||
|
|
||||||
func newIndexHandle(iHandle *common.IndexHandle) *indexHandle {
|
func newHandle(iHandle *common.IndexHandle, dHandle *common.DetailHandle) *handle {
|
||||||
return &indexHandle{iHandle}
|
return &handle{iHandle, dHandle}
|
||||||
}
|
}
|
||||||
|
|
||||||
type detailHandle struct {
|
type detailHandle struct {
|
||||||
|
@ -31,19 +32,22 @@ func newDetailHandle(dHandle *common.DetailHandle) *detailHandle {
|
||||||
func Hook(h *common.Handle) {
|
func Hook(h *common.Handle) {
|
||||||
h.WidgetAreaData()
|
h.WidgetAreaData()
|
||||||
h.GetPassword()
|
h.GetPassword()
|
||||||
|
handle := newHandle(common.NewIndexHandle(h), common.NewDetailHandle(h))
|
||||||
if h.Scene == constraints.Detail {
|
if h.Scene == constraints.Detail {
|
||||||
newDetailHandle(common.NewDetailHandle(h)).Detail()
|
handle.Detail()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
newIndexHandle(common.NewIndexHandle(h)).Index()
|
handle.Index()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *indexHandle) Index() {
|
func (h *handle) Index() {
|
||||||
i.Indexs()
|
h.CustomHeader()
|
||||||
|
h.Indexs()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *detailHandle) Detail() {
|
func (h *handle) Detail() {
|
||||||
d.Details()
|
h.CustomHeader()
|
||||||
|
h.Details()
|
||||||
}
|
}
|
||||||
|
|
||||||
func getHeaderImage(c *gin.Context) (r models.PostThumbnail) {
|
func getHeaderImage(c *gin.Context) (r models.PostThumbnail) {
|
||||||
|
|
|
@ -114,6 +114,7 @@ func GetThemeMods(theme string) (r ThemeMods, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
r.setThemeColorScheme(theme)
|
r.setThemeColorScheme(theme)
|
||||||
|
r.setThemeSupport(theme)
|
||||||
themeModes.Store(theme, r)
|
themeModes.Store(theme, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user