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"
|
|
|
|
|
2023-02-16 06:36:43 +00:00
|
|
|
type handle struct {
|
2023-02-11 15:51:07 +00:00
|
|
|
*common.IndexHandle
|
2023-02-16 06:36:43 +00:00
|
|
|
*common.DetailHandle
|
2023-02-09 12:49:33 +00:00
|
|
|
}
|
|
|
|
|
2023-02-16 06:36:43 +00:00
|
|
|
func newHandle(iHandle *common.IndexHandle, dHandle *common.DetailHandle) *handle {
|
|
|
|
return &handle{iHandle, dHandle}
|
2023-02-11 15:51:07 +00:00
|
|
|
}
|
2023-02-10 16:32:46 +00:00
|
|
|
|
2023-02-11 15:51:07 +00:00
|
|
|
type detailHandle struct {
|
|
|
|
*common.DetailHandle
|
|
|
|
}
|
|
|
|
|
|
|
|
func newDetailHandle(dHandle *common.DetailHandle) *detailHandle {
|
|
|
|
return &detailHandle{DetailHandle: dHandle}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Hook(h *common.Handle) {
|
|
|
|
h.WidgetAreaData()
|
|
|
|
h.GetPassword()
|
2023-02-16 06:36:43 +00:00
|
|
|
handle := newHandle(common.NewIndexHandle(h), common.NewDetailHandle(h))
|
2023-02-10 13:23:30 +00:00
|
|
|
if h.Scene == constraints.Detail {
|
2023-02-16 06:36:43 +00:00
|
|
|
handle.Detail()
|
2023-02-09 12:49:33 +00:00
|
|
|
return
|
|
|
|
}
|
2023-02-16 06:36:43 +00:00
|
|
|
handle.Index()
|
2023-02-09 12:49:33 +00:00
|
|
|
}
|
|
|
|
|
2023-02-16 06:36:43 +00:00
|
|
|
func (h *handle) Index() {
|
|
|
|
h.CustomHeader()
|
|
|
|
h.Indexs()
|
2023-02-09 12:49:33 +00:00
|
|
|
}
|
|
|
|
|
2023-02-16 06:36:43 +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": {},
|
|
|
|
}
|
|
|
|
}
|