wp-go/internal/theme/twentyfifteen/twentyfifteen.go

76 lines
1.6 KiB
Go
Raw Normal View History

2023-02-09 12:49:33 +00:00
package twentyfifteen
import (
2023-02-13 15:03:17 +00:00
"github.com/fthvgb1/wp-go/helper/slice"
"github.com/fthvgb1/wp-go/internal/pkg/cache"
2023-02-10 13:23:30 +00:00
"github.com/fthvgb1/wp-go/internal/pkg/constraints"
2023-02-13 15:03:17 +00:00
"github.com/fthvgb1/wp-go/internal/pkg/logs"
"github.com/fthvgb1/wp-go/internal/pkg/models"
2023-02-09 12:49:33 +00:00
"github.com/fthvgb1/wp-go/internal/theme/common"
2023-02-13 15:03:17 +00:00
"github.com/gin-gonic/gin"
2023-02-09 12:49:33 +00:00
)
const ThemeName = "twentyfifteen"
type handle struct {
*common.IndexHandle
*common.DetailHandle
2023-02-09 12:49:33 +00:00
}
func newHandle(iHandle *common.IndexHandle, dHandle *common.DetailHandle) *handle {
return &handle{iHandle, dHandle}
}
type detailHandle struct {
*common.DetailHandle
}
func newDetailHandle(dHandle *common.DetailHandle) *detailHandle {
return &detailHandle{DetailHandle: dHandle}
}
func Hook(h *common.Handle) {
h.WidgetAreaData()
h.GetPassword()
handle := newHandle(common.NewIndexHandle(h), common.NewDetailHandle(h))
2023-02-10 13:23:30 +00:00
if h.Scene == constraints.Detail {
handle.Detail()
2023-02-09 12:49:33 +00:00
return
}
handle.Index()
2023-02-09 12:49:33 +00:00
}
func (h *handle) Index() {
h.CustomHeader()
h.Indexs()
2023-02-09 12:49:33 +00:00
}
func (h *handle) Detail() {
h.CustomHeader()
h.Details()
2023-02-09 12:49:33 +00:00
}
2023-02-13 15:03:17 +00:00
func getHeaderImage(c *gin.Context) (r models.PostThumbnail) {
r.Path = "/wp-content/themes/twentyseventeen/assets/images/header.jpg"
r.Width = 2000
r.Height = 1200
hs, err := cache.GetHeaderImages(c, ThemeName)
if err != nil {
logs.ErrPrintln(err, "获取页眉背景图失败")
} else if len(hs) > 0 && err == nil {
_, r = slice.Rand(hs)
}
r.Sizes = "100vw"
return
}
2023-02-14 11:47:47 +00:00
func ThemeSupport() map[string]struct{} {
return map[string]struct{}{
"custom-background": {},
"wp-custom-logo": {},
"responsive-embeds": {},
"post-formats": {},
}
}