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-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-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 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
err = json.Unmarshal(b, &themesupport)
|
|
|
|
logs.ErrPrintln(err, "解析themesupport失败")
|
|
|
|
bytes, err := fs.ReadFile("twentyfifteen/colorscheme.json")
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
err = json.Unmarshal(bytes, &colorscheme)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
logs.ErrPrintln(err, "解析colorscheme失败")
|
|
|
|
}
|
|
|
|
|
2023-03-14 10:35:48 +00:00
|
|
|
var pipe = wp.HandlePipe(wp.Render, widget.IsCategory, dispatch)
|
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-01 05:17:12 +00:00
|
|
|
func dispatch(next wp.HandleFn[*wp.Handle], h *wp.Handle) {
|
2023-03-12 12:41:10 +00:00
|
|
|
components.WidgetArea(h)
|
2023-02-11 15:51:07 +00:00
|
|
|
h.GetPassword()
|
2023-03-12 12:41:10 +00:00
|
|
|
h.PushComponentFilterFn(widgets.SearchFormArgs, func(h *wp.Handle, s string) string {
|
2023-03-11 15:59:00 +00:00
|
|
|
return strings.ReplaceAll(s, `class="search-submit"`, `class="search-submit screen-reader-text"`)
|
|
|
|
})
|
2023-03-02 15:49:28 +00:00
|
|
|
wphandle.RegisterPlugins(h, config.GetConfig().Plugins...)
|
|
|
|
|
2023-03-04 06:44:51 +00:00
|
|
|
h.PushCacheGroupHeadScript("CalCustomBackGround", 10, CalCustomBackGround, colorSchemeCss)
|
2023-03-01 05:17:12 +00:00
|
|
|
h.PushHandleFn(constraints.AllStats, wp.NewHandleFn(customHeader, 10))
|
2023-02-28 15:38:23 +00:00
|
|
|
switch h.Scene() {
|
2023-02-23 15:42:51 +00:00
|
|
|
case constraints.Detail:
|
2023-02-24 11:43:12 +00:00
|
|
|
detail(next, h.Detail)
|
2023-02-23 15:42:51 +00:00
|
|
|
default:
|
2023-02-24 11:43:12 +00:00
|
|
|
index(next, h.Index)
|
2023-02-09 12:49:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-01 05:17:12 +00:00
|
|
|
func index(next wp.HandleFn[*wp.Handle], i *wp.IndexHandle) {
|
2023-02-23 15:42:51 +00:00
|
|
|
i.Indexs()
|
2023-02-09 12:49:33 +00:00
|
|
|
}
|
|
|
|
|
2023-03-01 05:17:12 +00:00
|
|
|
func detail(fn wp.HandleFn[*wp.Handle], d *wp.DetailHandle) {
|
2023-02-23 15:42:51 +00:00
|
|
|
d.Details()
|
2023-02-09 12:49:33 +00:00
|
|
|
}
|