2023-02-09 12:49:33 +00:00
|
|
|
package twentyfifteen
|
|
|
|
|
|
|
|
import (
|
2023-05-04 12:37:06 +00:00
|
|
|
"github.com/fthvgb1/wp-go/app/pkg/constraints"
|
|
|
|
"github.com/fthvgb1/wp-go/app/pkg/constraints/widgets"
|
2024-01-21 13:29:36 +00:00
|
|
|
"github.com/fthvgb1/wp-go/app/pkg/models"
|
2023-05-04 12:37:06 +00:00
|
|
|
"github.com/fthvgb1/wp-go/app/plugins"
|
|
|
|
"github.com/fthvgb1/wp-go/app/theme/wp"
|
|
|
|
"github.com/fthvgb1/wp-go/app/theme/wp/components"
|
2024-01-13 13:15:54 +00:00
|
|
|
"github.com/fthvgb1/wp-go/app/theme/wp/middleware"
|
2023-05-04 12:37:06 +00:00
|
|
|
"github.com/fthvgb1/wp-go/app/wpconfig"
|
2024-01-21 13:29:36 +00:00
|
|
|
"github.com/fthvgb1/wp-go/cache/reload"
|
2023-03-11 15:59:00 +00:00
|
|
|
"strings"
|
2023-02-09 12:49:33 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const ThemeName = "twentyfifteen"
|
|
|
|
|
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-04 15:02:54 +00:00
|
|
|
}
|
|
|
|
|
2023-04-07 14:59:07 +00:00
|
|
|
func configs(h *wp.Handle) {
|
2023-08-26 14:01:20 +00:00
|
|
|
h.AddActionFilter(widgets.Search, func(h *wp.Handle, s string, args ...any) string {
|
2023-03-11 15:59:00 +00:00
|
|
|
return strings.ReplaceAll(s, `class="search-submit"`, `class="search-submit screen-reader-text"`)
|
|
|
|
})
|
2023-05-03 15:57:49 +00:00
|
|
|
wp.InitPipe(h)
|
2024-01-13 13:15:54 +00:00
|
|
|
middleware.CommonMiddleware(h)
|
2024-01-18 15:29:50 +00:00
|
|
|
setPaginationAndRender(h)
|
2023-06-15 10:00:57 +00:00
|
|
|
h.PushCacheGroupHeadScript(constraints.AllScene, "CalCustomBackGround", 10.005, CalCustomBackGround)
|
|
|
|
h.PushCacheGroupHeadScript(constraints.AllScene, "colorSchemeCss", 10.0056, colorSchemeCss)
|
2023-04-04 15:02:54 +00:00
|
|
|
h.CommonComponents()
|
2023-04-19 07:27:58 +00:00
|
|
|
components.WidgetArea(h)
|
2024-01-21 13:29:36 +00:00
|
|
|
h.PushRender(constraints.AllScene, wp.NewHandleFn(renderCustomHeader, 20.5, "renderCustomHeader"))
|
2023-06-15 10:00:57 +00:00
|
|
|
wp.PushIndexHandler(constraints.PipeRender, h, wp.NewHandleFn(wp.IndexRender, 50.005, "wp.IndexRender"))
|
|
|
|
h.PushRender(constraints.Detail, wp.NewHandleFn(wp.DetailRender, 50.005, "wp.DetailRender"))
|
|
|
|
h.PushRender(constraints.Detail, wp.NewHandleFn(postThumb, 60.005, "postThumb"))
|
|
|
|
h.PushDataHandler(constraints.Detail, wp.NewHandleFn(wp.Detail, 100.005, "wp.Detail"))
|
|
|
|
wp.PushIndexHandler(constraints.PipeData, h, wp.NewHandleFn(wp.Index, 100.005, "wp.Index"))
|
|
|
|
h.PushDataHandler(constraints.AllScene, wp.NewHandleFn(wp.PreCodeAndStats, 80.005, "wp.PreCodeAndStats"))
|
|
|
|
h.PushRender(constraints.AllScene, wp.NewHandleFn(wp.PreTemplate, 70.005, "wp.PreTemplate"))
|
2023-04-17 09:24:42 +00:00
|
|
|
}
|
|
|
|
|
2024-01-18 15:29:50 +00:00
|
|
|
func setPaginationAndRender(h *wp.Handle) {
|
|
|
|
h.PushHandler(constraints.PipeRender, constraints.Detail, wp.NewHandleFn(func(hh *wp.Handle) {
|
|
|
|
d := hh.GetDetailHandle()
|
|
|
|
d.CommentRender = plugins.CommentRender()
|
|
|
|
d.CommentPageEle = plugins.TwentyFifteenCommentPagination()
|
|
|
|
}, 150, "setPaginationAndRender"))
|
|
|
|
|
|
|
|
wp.PushIndexHandler(constraints.PipeRender, h, wp.NewHandleFn(func(hh *wp.Handle) {
|
|
|
|
i := hh.GetIndexHandle()
|
|
|
|
i.SetPageEle(plugins.TwentyFifteenPagination())
|
|
|
|
}, 150, "setPaginationAndRender"))
|
|
|
|
}
|
|
|
|
|
2023-04-17 09:24:42 +00:00
|
|
|
func postThumb(h *wp.Handle) {
|
2024-01-18 15:29:50 +00:00
|
|
|
d := h.GetDetailHandle()
|
|
|
|
if d.Post.Thumbnail.Path != "" {
|
2024-01-21 13:29:36 +00:00
|
|
|
d.Post.Thumbnail = getPostThumbs(d.Post.Id, d.Post)
|
2023-04-17 09:24:42 +00:00
|
|
|
}
|
2023-02-09 12:49:33 +00:00
|
|
|
}
|
2024-01-21 13:29:36 +00:00
|
|
|
|
|
|
|
var getPostThumbs = reload.BuildMapFn[uint64]("twentyFifteen-post-thumbnail", postThumbs)
|
|
|
|
|
|
|
|
func postThumbs(post models.Posts) models.PostThumbnail {
|
|
|
|
return wpconfig.Thumbnail(post.Thumbnail.OriginAttachmentData, "post-thumbnail", "")
|
|
|
|
}
|
|
|
|
|
|
|
|
func renderCustomHeader(h *wp.Handle) {
|
|
|
|
h.SetData("customHeader", customHeader(h))
|
|
|
|
}
|