wp-go/app/theme/twentyfifteen/twentyfifteen.go

80 lines
2.8 KiB
Go
Raw Normal View History

2023-02-09 12:49:33 +00:00
package twentyfifteen
import (
2023-02-18 15:35:39 +00:00
"embed"
"encoding/json"
2023-05-04 12:37:06 +00:00
"github.com/fthvgb1/wp-go/app/pkg/config"
"github.com/fthvgb1/wp-go/app/pkg/constraints"
"github.com/fthvgb1/wp-go/app/pkg/constraints/widgets"
"github.com/fthvgb1/wp-go/app/pkg/logs"
"github.com/fthvgb1/wp-go/app/plugins"
"github.com/fthvgb1/wp-go/app/plugins/wphandle"
"github.com/fthvgb1/wp-go/app/theme/wp"
"github.com/fthvgb1/wp-go/app/theme/wp/components"
"github.com/fthvgb1/wp-go/app/theme/wp/components/widget"
"github.com/fthvgb1/wp-go/app/wpconfig"
"strings"
2023-02-09 12:49:33 +00:00
)
const ThemeName = "twentyfifteen"
2023-02-18 15:35:39 +00:00
func Init(fs embed.FS) {
b, err := fs.ReadFile("twentyfifteen/themesupport.json")
if err != nil {
2023-04-07 14:59:07 +00:00
logs.Error(err, "读取themesupport.json失败")
2023-02-18 15:35:39 +00:00
return
}
err = json.Unmarshal(b, &themesupport)
2023-04-07 14:59:07 +00:00
if err != nil {
logs.Error(err, "解析themesupport失败")
return
}
2023-02-18 15:35:39 +00:00
bytes, err := fs.ReadFile("twentyfifteen/colorscheme.json")
if err != nil {
2023-04-07 14:59:07 +00:00
logs.Error(err, "读取colorscheme.json失败")
2023-02-18 15:35:39 +00:00
return
}
err = json.Unmarshal(bytes, &colorscheme)
if err != nil {
2023-04-07 14:59:07 +00:00
logs.Error(err, "解析colorscheme失败")
2023-02-18 15:35:39 +00:00
return
}
}
2023-03-01 05:17:12 +00:00
func Hook(h *wp.Handle) {
2023-05-03 15:57:49 +00:00
wp.Run(h, configs)
}
2023-04-07 14:59:07 +00:00
func configs(h *wp.Handle) {
2023-05-03 15:57:49 +00:00
wphandle.UsePlugins(h)
conf := config.GetConfig()
2023-03-27 03:37:24 +00:00
h.PushComponentFilterFn(widgets.Search, func(h *wp.Handle, s string, args ...any) string {
return strings.ReplaceAll(s, `class="search-submit"`, `class="search-submit screen-reader-text"`)
})
2023-05-03 15:57:49 +00:00
wp.InitPipe(h)
h.PushHandler(constraints.PipeMiddleware, constraints.Home,
wp.NewHandleFn(widget.IsCategory, 100, "widget.IsCategory"))
h.Index.SetPageEle(plugins.TwentyFifteenPagination())
2023-04-30 13:17:33 +00:00
h.PushCacheGroupHeadScript(constraints.AllScene, "CalCustomBackGround", 10, CalCustomBackGround)
h.PushCacheGroupHeadScript(constraints.AllScene, "colorSchemeCss", 10, colorSchemeCss)
h.CommonComponents()
h.Index.SetListPlugin(wp.PostsPlugins(wp.PostPlugin(), wp.GetListPostPlugins(conf.ListPagePlugins, wp.ListPostPlugins())...))
2023-04-19 07:27:58 +00:00
components.WidgetArea(h)
2023-04-29 14:05:24 +00:00
wp.ReplyCommentJs(h)
2023-04-24 13:51:43 +00:00
h.SetData("customHeader", customHeader(h))
2023-04-21 17:12:39 +00:00
h.PushRender(constraints.AllStats, wp.NewHandleFn(wp.IndexRender, 50, "wp.IndexRender"))
h.PushRender(constraints.Detail, wp.NewHandleFn(wp.DetailRender, 50, "wp.DetailRender"))
h.PushRender(constraints.Detail, wp.NewHandleFn(postThumb, 60, "postThumb"))
h.PushDataHandler(constraints.Detail, wp.NewHandleFn(wp.Details, 100, "wp.Details"))
h.PushDataHandler(constraints.AllScene, wp.NewHandleFn(wp.Indexs, 100, "wp.Indexs"))
h.PushDataHandler(constraints.AllScene, wp.NewHandleFn(wp.PreCodeAndStats, 80, "wp.PreCodeAndStats"))
h.PushRender(constraints.AllScene, wp.NewHandleFn(wp.PreTemplate, 70, "wp.PreTemplate"))
2023-04-17 09:24:42 +00:00
}
func postThumb(h *wp.Handle) {
if h.Detail.Post.Thumbnail.Path != "" {
h.Detail.Post.Thumbnail = wpconfig.Thumbnail(h.Detail.Post.Thumbnail.OriginAttachmentData, "post-thumbnail", "")
}
2023-02-09 12:49:33 +00:00
}