2023-02-09 12:49:33 +00:00
|
|
|
package twentyfifteen
|
|
|
|
|
|
|
|
import (
|
2023-02-18 15:35:39 +00:00
|
|
|
"embed"
|
|
|
|
"encoding/json"
|
2023-03-02 15:49:28 +00:00
|
|
|
"github.com/fthvgb1/wp-go/internal/pkg/config"
|
2023-02-10 13:23:30 +00:00
|
|
|
"github.com/fthvgb1/wp-go/internal/pkg/constraints"
|
2023-03-12 12:41:10 +00:00
|
|
|
"github.com/fthvgb1/wp-go/internal/pkg/constraints/widgets"
|
2023-02-18 15:35:39 +00:00
|
|
|
"github.com/fthvgb1/wp-go/internal/pkg/logs"
|
2023-04-09 13:51:12 +00:00
|
|
|
"github.com/fthvgb1/wp-go/internal/plugins"
|
2023-03-02 15:49:28 +00:00
|
|
|
"github.com/fthvgb1/wp-go/internal/plugins/wphandle"
|
2023-03-01 05:17:12 +00:00
|
|
|
"github.com/fthvgb1/wp-go/internal/theme/wp"
|
2023-03-12 12:41:10 +00:00
|
|
|
"github.com/fthvgb1/wp-go/internal/theme/wp/components"
|
2023-03-14 10:35:48 +00:00
|
|
|
"github.com/fthvgb1/wp-go/internal/theme/wp/components/widget"
|
2023-04-17 09:24:42 +00:00
|
|
|
"github.com/fthvgb1/wp-go/internal/wpconfig"
|
2023-03-11 15:59:00 +00:00
|
|
|
"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-04-19 07:27:58 +00:00
|
|
|
var pipe = wp.HandlePipe(wp.ExecuteHandleFn, widget.MiddleWare(ready, wp.DataHandle)...)
|
2023-02-10 16:32:46 +00:00
|
|
|
|
2023-03-01 05:17:12 +00:00
|
|
|
func Hook(h *wp.Handle) {
|
2023-02-24 11:43:12 +00:00
|
|
|
pipe(h)
|
|
|
|
}
|
|
|
|
|
2023-03-17 05:35:22 +00:00
|
|
|
func ready(next wp.HandleFn[*wp.Handle], h *wp.Handle) {
|
2023-04-04 15:02:54 +00:00
|
|
|
wp.InitThemeArgAndConfig(configs, h)
|
2023-02-11 15:51:07 +00:00
|
|
|
h.GetPassword()
|
2023-04-04 15:02:54 +00:00
|
|
|
next(h)
|
|
|
|
}
|
|
|
|
|
2023-04-07 14:59:07 +00:00
|
|
|
func configs(h *wp.Handle) {
|
2023-04-09 13:51:12 +00:00
|
|
|
conf := config.GetConfig()
|
2023-03-27 03:37:24 +00:00
|
|
|
h.PushComponentFilterFn(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-04-09 13:51:12 +00:00
|
|
|
h.Index.SetPageEle(plugins.TwentyFifteenPagination())
|
|
|
|
wphandle.RegisterPlugins(h, conf.Plugins...)
|
2023-03-04 06:44:51 +00:00
|
|
|
h.PushCacheGroupHeadScript("CalCustomBackGround", 10, CalCustomBackGround, colorSchemeCss)
|
2023-04-04 15:02:54 +00:00
|
|
|
h.CommonComponents()
|
2023-04-09 13:51:12 +00:00
|
|
|
h.Index.SetListPlugin(wp.PostsPlugins(wp.PostPlugin(), wp.GetListPostPlugins(conf.ListPagePlugins, wp.ListPostPlugins())...))
|
2023-04-19 07:27:58 +00:00
|
|
|
components.WidgetArea(h)
|
|
|
|
h.PushRender(constraints.AllStats, wp.NewHandleFn(customHeader, 10))
|
|
|
|
h.PushRender(constraints.AllStats, wp.NewHandleFn(wp.IndexRender, 50))
|
|
|
|
h.PushRender(constraints.Detail, wp.NewHandleFn(wp.DetailRender, 50))
|
|
|
|
h.PushRender(constraints.Detail, wp.NewHandleFn(postThumb, 60))
|
|
|
|
h.PushDataHandler(constraints.Detail, wp.NewHandleFn(wp.Details, 100))
|
|
|
|
h.PushDataHandler(constraints.AllScene, wp.NewHandleFn(wp.Indexs, 100))
|
|
|
|
h.PushDataHandler(constraints.AllScene, wp.NewHandleFn(wp.PreCodeAndStats, 80))
|
|
|
|
h.PushDataHandler(constraints.AllScene, wp.NewHandleFn(wp.PreTemplate, 70))
|
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
|
|
|
}
|