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

72 lines
1.5 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 indexHandle struct {
*common.IndexHandle
2023-02-09 12:49:33 +00:00
}
func newIndexHandle(iHandle *common.IndexHandle) *indexHandle {
return &indexHandle{iHandle}
}
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-10 13:23:30 +00:00
if h.Scene == constraints.Detail {
newDetailHandle(common.NewDetailHandle(h)).Detail()
2023-02-09 12:49:33 +00:00
return
}
newIndexHandle(common.NewIndexHandle(h)).Index()
2023-02-09 12:49:33 +00:00
}
func (i *indexHandle) Index() {
2023-02-14 15:28:45 +00:00
i.Indexs()
2023-02-09 12:49:33 +00:00
}
func (d *detailHandle) Detail() {
2023-02-14 15:28:45 +00:00
d.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": {},
}
}