优化代码

This commit is contained in:
xing 2023-05-08 21:43:20 +08:00
parent 036f1a1212
commit 4058ff9b7b
14 changed files with 320 additions and 475 deletions

2
.gitignore vendored
View File

@ -2,4 +2,4 @@
wp-go.iml wp-go.iml
config.yaml config.yaml
err.log err.log
./plugins/ /plugins/

View File

@ -0,0 +1,11 @@
package apply
var fn any
func SetFn(f any) {
fn = f
}
func UsePlugins() any {
return fn
}

View File

@ -4,6 +4,7 @@ import (
"errors" "errors"
"github.com/fthvgb1/wp-go/app/pkg/config" "github.com/fthvgb1/wp-go/app/pkg/config"
"github.com/fthvgb1/wp-go/app/pkg/logs" "github.com/fthvgb1/wp-go/app/pkg/logs"
"github.com/fthvgb1/wp-go/app/plugins/wphandle/apply"
"github.com/fthvgb1/wp-go/app/plugins/wphandle/enlightjs" "github.com/fthvgb1/wp-go/app/plugins/wphandle/enlightjs"
"github.com/fthvgb1/wp-go/app/plugins/wphandle/hiddenlogin" "github.com/fthvgb1/wp-go/app/plugins/wphandle/hiddenlogin"
"github.com/fthvgb1/wp-go/app/theme/wp" "github.com/fthvgb1/wp-go/app/theme/wp"
@ -65,5 +66,7 @@ func LoadPlugins() {
} }
RegisterPlugin(name, plu) RegisterPlugin(name, plu)
} }
apply.SetFn(func(h *wp.Handle) {
UsePlugins(h)
})
} }

View File

@ -1,9 +1,9 @@
package theme package theme
import ( import (
"github.com/fthvgb1/wp-go/app/theme/twentyfifteen"
"github.com/fthvgb1/wp-go/app/theme/wp" "github.com/fthvgb1/wp-go/app/theme/wp"
"github.com/fthvgb1/wp-go/safety" "github.com/fthvgb1/wp-go/safety"
"net/http"
) )
var themeMap = safety.NewMap[string, func(*wp.Handle)]() var themeMap = safety.NewMap[string, func(*wp.Handle)]()
@ -21,5 +21,5 @@ func Hook(themeName string, h *wp.Handle) {
fn(h) fn(h)
return return
} }
h.C.String(http.StatusNotFound, "404") twentyfifteen.Hook(h)
} }

View File

@ -9,9 +9,7 @@ import (
func InitTheme() { func InitTheme() {
AddThemeHookFunc(twentyfifteen.ThemeName, twentyfifteen.Hook) AddThemeHookFunc(twentyfifteen.ThemeName, twentyfifteen.Hook)
twentyfifteen.Init(TemplateFs)
AddThemeHookFunc(twentyseventeen.ThemeName, twentyseventeen.Hook) AddThemeHookFunc(twentyseventeen.ThemeName, twentyseventeen.Hook)
twentyseventeen.Init(TemplateFs)
} }
func GetCurrentTemplateName() string { func GetCurrentTemplateName() string {

View File

@ -1,68 +0,0 @@
{
"default": {
"label": "Default",
"colors": [
"#f1f1f1",
"#ffffff",
"#ffffff",
"#333333",
"#333333",
"#f7f7f7"
]
},
"dark": {
"label": "Dark",
"colors": [
"#111111",
"#202020",
"#202020",
"#bebebe",
"#bebebe",
"#1b1b1b"
]
},
"yellow": {
"label": "Yellow",
"colors": [
"#f4ca16",
"#ffdf00",
"#ffffff",
"#111111",
"#111111",
"#f1f1f1"
]
},
"pink": {
"label": "Pink",
"colors": [
"#ffe5d1",
"#e53b51",
"#ffffff",
"#352712",
"#ffffff",
"#f1f1f1"
]
},
"purple": {
"label": "Purple",
"colors": [
"#674970",
"#2e2256",
"#ffffff",
"#2e2256",
"#ffffff",
"#f1f1f1"
]
},
"blue": {
"label": "Blue",
"colors": [
"#e9f2f9",
"#55c3dc",
"#ffffff",
"#22313f",
"#ffffff",
"#f1f1f1"
]
}
}

View File

@ -30,5 +30,200 @@ type EditorGradientPresets struct {
Gradient string `json:"gradient"` Gradient string `json:"gradient"`
} }
var themesupport themeSupport var themesupport = themeSupport{
var colorscheme map[string]ColorScheme CustomBackground: customBackground{
DefaultImage: "",
DefaultPreset: "default",
DefaultPositionX: "left",
DefaultPositionY: "top",
DefaultSize: "auto",
DefaultRepeat: "repeat",
DefaultAttachment: "fixed",
DefaultColor: "f1f1f1",
WpHeadCallback: "_custom_background_cb",
AdminHeadCallback: "",
AdminPreviewCallback: "",
},
EditorColorPalette: []EditorColorPalette{
{
Name: "暗灰色",
Slug: "dark-gray",
Color: "#111",
},
{
Name: "亮灰色",
Slug: "light-gray",
Color: "#f1f1f1",
},
{
Name: "白色",
Slug: "white",
Color: "#fff",
},
{
Name: "黄色",
Slug: "yellow",
Color: "#f4ca16",
},
{
Name: "暗棕色",
Slug: "dark-brown",
Color: "#352712",
},
{
Name: "粉色",
Slug: "medium-pink",
Color: "#e53b51",
},
{
Name: "浅粉色",
Slug: "light-pink",
Color: "#ffe5d1",
},
{
Name: "暗紫色",
Slug: "dark-purple",
Color: "#2e2256",
},
{
Name: "紫色",
Slug: "purple",
Color: "#674970",
},
{
Name: "蓝灰色",
Slug: "blue-gray",
Color: "#22313f",
},
{
Name: "亮蓝色",
Slug: "bright-blue",
Color: "#55c3dc",
},
{
Name: "浅蓝色",
Slug: "light-blue",
Color: "#e9f2f9",
},
},
EditorGradientPresets: []EditorGradientPresets{
{
Name: "Dark Gray Gradient",
Slug: "dark-gray-gradient-gradient",
Gradient: "linear-gradient(90deg, rgba(17,17,17,1) 0%, rgba(42,42,42,1) 100%)",
},
{
Name: "Light Gray Gradient",
Slug: "light-gray-gradient",
Gradient: "linear-gradient(90deg, rgba(241,241,241,1) 0%, rgba(215,215,215,1) 100%)",
},
{
Name: "White Gradient",
Slug: "white-gradient",
Gradient: "linear-gradient(90deg, rgba(255,255,255,1) 0%, rgba(230,230,230,1) 100%)",
},
{
Name: "Yellow Gradient",
Slug: "yellow-gradient",
Gradient: "linear-gradient(90deg, rgba(244,202,22,1) 0%, rgba(205,168,10,1) 100%)",
},
{
Name: "Dark Brown Gradient",
Slug: "dark-brown-gradient",
Gradient: "linear-gradient(90deg, rgba(53,39,18,1) 0%, rgba(91,67,31,1) 100%)",
},
{
Name: "Medium Pink Gradient",
Slug: "medium-pink-gradient",
Gradient: "linear-gradient(90deg, rgba(229,59,81,1) 0%, rgba(209,28,51,1) 100%)",
},
{
Name: "Light Pink Gradient",
Slug: "light-pink-gradient",
Gradient: "linear-gradient(90deg, rgba(255,229,209,1) 0%, rgba(255,200,158,1) 100%)",
},
{
Name: "Dark Purple Gradient",
Slug: "dark-purple-gradient",
Gradient: "linear-gradient(90deg, rgba(46,34,86,1) 0%, rgba(66,48,123,1) 100%)",
},
{
Name: "Purple Gradient",
Slug: "purple-gradient",
Gradient: "linear-gradient(90deg, rgba(103,73,112,1) 0%, rgba(131,93,143,1) 100%)",
},
{
Name: "Blue Gray Gradient",
Slug: "blue-gray-gradient",
Gradient: "linear-gradient(90deg, rgba(34,49,63,1) 0%, rgba(52,75,96,1) 100%)",
},
{
Name: "Bright Blue Gradient",
Slug: "bright-blue-gradient",
Gradient: "linear-gradient(90deg, rgba(85,195,220,1) 0%, rgba(43,180,211,1) 100%)",
},
{
Name: "Light Blue Gradient",
Slug: "light-blue-gradient",
Gradient: "linear-gradient(90deg, rgba(233,242,249,1) 0%, rgba(193,218,238,1) 100%)",
},
},
}
var colorscheme = map[string]ColorScheme{
"default": {
Label: "Default",
Colors: []string{
"#f1f1f1",
"#ffffff",
"#ffffff",
"#333333",
"#333333",
"#f7f7f7",
},
},
"dark": {
Label: "Dark",
Colors: []string{
"#111111",
"#202020",
"#202020",
"#bebebe",
"#bebebe",
"#1b1b1b",
},
},
"pink": {
Label: "Pink",
Colors: []string{
"#ffe5d1",
"#e53b51",
"#ffffff",
"#352712",
"#ffffff",
"#f1f1f1",
},
},
"purple": {
Label: "Purple",
Colors: []string{
"#674970",
"#2e2256",
"#ffffff",
"#2e2256",
"#ffffff",
"#f1f1f1",
},
},
"blue": {
Label: "Blue",
Colors: []string{
"#e9f2f9",
"#55c3dc",
"#ffffff",
"#22313f",
"#ffffff",
"#f1f1f1",
},
},
}

View File

@ -1,196 +0,0 @@
{
"core-block-patterns": true,
"widgets-block-editor": true,
"automatic-feed-links": true,
"title-tag": true,
"post-thumbnails": true,
"menus": true,
"html5": [
"search-form",
"comment-form",
"comment-list",
"gallery",
"caption",
"script",
"style",
"navigation-widgets"
],
"post-formats": [
"aside",
"image",
"video",
"quote",
"link",
"gallery",
"status",
"audio",
"chat"
],
"custom-logo": {
"width": 248,
"height": 248,
"flex-width": false,
"flex-height": true,
"header-text": "",
"unlink-homepage-logo": false
},
"custom-background": {
"default-image": "",
"default-preset": "default",
"default-position-x": "left",
"default-position-y": "top",
"default-size": "auto",
"default-repeat": "repeat",
"default-attachment": "fixed",
"default-color": "f1f1f1",
"wp-head-callback": "_custom_background_cb",
"admin-head-callback": "",
"admin-preview-callback": ""
},
"editor-style": true,
"editor-styles": true,
"wp-block-styles": true,
"responsive-embeds": true,
"editor-color-palette": [
{
"name": "暗灰色",
"slug": "dark-gray",
"color": "#111"
},
{
"name": "亮灰色",
"slug": "light-gray",
"color": "#f1f1f1"
},
{
"name": "白色",
"slug": "white",
"color": "#fff"
},
{
"name": "黄色",
"slug": "yellow",
"color": "#f4ca16"
},
{
"name": "暗棕色",
"slug": "dark-brown",
"color": "#352712"
},
{
"name": "粉色",
"slug": "medium-pink",
"color": "#e53b51"
},
{
"name": "浅粉色",
"slug": "light-pink",
"color": "#ffe5d1"
},
{
"name": "暗紫色",
"slug": "dark-purple",
"color": "#2e2256"
},
{
"name": "紫色",
"slug": "purple",
"color": "#674970"
},
{
"name": "蓝灰色",
"slug": "blue-gray",
"color": "#22313f"
},
{
"name": "亮蓝色",
"slug": "bright-blue",
"color": "#55c3dc"
},
{
"name": "浅蓝色",
"slug": "light-blue",
"color": "#e9f2f9"
}
],
"editor-gradient-presets": [
{
"name": "Dark Gray Gradient",
"slug": "dark-gray-gradient-gradient",
"gradient": "linear-gradient(90deg, rgba(17,17,17,1) 0%, rgba(42,42,42,1) 100%)"
},
{
"name": "Light Gray Gradient",
"slug": "light-gray-gradient",
"gradient": "linear-gradient(90deg, rgba(241,241,241,1) 0%, rgba(215,215,215,1) 100%)"
},
{
"name": "White Gradient",
"slug": "white-gradient",
"gradient": "linear-gradient(90deg, rgba(255,255,255,1) 0%, rgba(230,230,230,1) 100%)"
},
{
"name": "Yellow Gradient",
"slug": "yellow-gradient",
"gradient": "linear-gradient(90deg, rgba(244,202,22,1) 0%, rgba(205,168,10,1) 100%)"
},
{
"name": "Dark Brown Gradient",
"slug": "dark-brown-gradient",
"gradient": "linear-gradient(90deg, rgba(53,39,18,1) 0%, rgba(91,67,31,1) 100%)"
},
{
"name": "Medium Pink Gradient",
"slug": "medium-pink-gradient",
"gradient": "linear-gradient(90deg, rgba(229,59,81,1) 0%, rgba(209,28,51,1) 100%)"
},
{
"name": "Light Pink Gradient",
"slug": "light-pink-gradient",
"gradient": "linear-gradient(90deg, rgba(255,229,209,1) 0%, rgba(255,200,158,1) 100%)"
},
{
"name": "Dark Purple Gradient",
"slug": "dark-purple-gradient",
"gradient": "linear-gradient(90deg, rgba(46,34,86,1) 0%, rgba(66,48,123,1) 100%)"
},
{
"name": "Purple Gradient",
"slug": "purple-gradient",
"gradient": "linear-gradient(90deg, rgba(103,73,112,1) 0%, rgba(131,93,143,1) 100%)"
},
{
"name": "Blue Gray Gradient",
"slug": "blue-gray-gradient",
"gradient": "linear-gradient(90deg, rgba(34,49,63,1) 0%, rgba(52,75,96,1) 100%)"
},
{
"name": "Bright Blue Gradient",
"slug": "bright-blue-gradient",
"gradient": "linear-gradient(90deg, rgba(85,195,220,1) 0%, rgba(43,180,211,1) 100%)"
},
{
"name": "Light Blue Gradient",
"slug": "light-blue-gradient",
"gradient": "linear-gradient(90deg, rgba(233,242,249,1) 0%, rgba(193,218,238,1) 100%)"
}
],
"customize-selective-refresh-widgets": true,
"custom-header": {
"default-image": "",
"random-default": false,
"width": 954,
"height": 1300,
"flex-height": false,
"flex-width": false,
"default-text-color": "333333",
"header-text": true,
"uploads": true,
"wp-head-callback": "twentyfifteen_header_style",
"admin-head-callback": "",
"admin-preview-callback": "",
"video": false,
"video-active-callback": "is_front_page"
},
"widgets": true
}

View File

@ -1,14 +1,10 @@
package twentyfifteen package twentyfifteen
import ( import (
"embed"
"encoding/json"
"github.com/fthvgb1/wp-go/app/pkg/config" "github.com/fthvgb1/wp-go/app/pkg/config"
"github.com/fthvgb1/wp-go/app/pkg/constraints" "github.com/fthvgb1/wp-go/app/pkg/constraints"
"github.com/fthvgb1/wp-go/app/pkg/constraints/widgets" "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"
"github.com/fthvgb1/wp-go/app/plugins/wphandle"
"github.com/fthvgb1/wp-go/app/theme/wp" "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"
"github.com/fthvgb1/wp-go/app/theme/wp/components/widget" "github.com/fthvgb1/wp-go/app/theme/wp/components/widget"
@ -18,35 +14,11 @@ import (
const ThemeName = "twentyfifteen" const ThemeName = "twentyfifteen"
func Init(fs embed.FS) {
b, err := fs.ReadFile("twentyfifteen/themesupport.json")
if err != nil {
logs.Error(err, "读取themesupport.json失败")
return
}
err = json.Unmarshal(b, &themesupport)
if err != nil {
logs.Error(err, "解析themesupport失败")
return
}
bytes, err := fs.ReadFile("twentyfifteen/colorscheme.json")
if err != nil {
logs.Error(err, "读取colorscheme.json失败")
return
}
err = json.Unmarshal(bytes, &colorscheme)
if err != nil {
logs.Error(err, "解析colorscheme失败")
return
}
}
func Hook(h *wp.Handle) { func Hook(h *wp.Handle) {
wp.Run(h, configs) wp.Run(h, configs)
} }
func configs(h *wp.Handle) { func configs(h *wp.Handle) {
wphandle.UsePlugins(h)
conf := config.GetConfig() conf := config.GetConfig()
h.PushComponentFilterFn(widgets.Search, func(h *wp.Handle, s string, args ...any) string { 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"`) return strings.ReplaceAll(s, `class="search-submit"`, `class="search-submit screen-reader-text"`)

View File

@ -22,13 +22,7 @@ type Blog struct {
type HomepageSection struct { type HomepageSection struct {
Thumbnail string `json:"thumbnail"` Thumbnail string `json:"thumbnail"`
} }
type Posts struct {
Num0 string `json:"0"`
About About `json:"about"`
Contact Contact `json:"contact"`
Blog Blog `json:"blog"`
HomepageSection HomepageSection `json:"homepage-section"`
}
type ImageEspresso struct { type ImageEspresso struct {
PostTitle string `json:"post_title"` PostTitle string `json:"post_title"`
File string `json:"file"` File string `json:"file"`
@ -46,6 +40,11 @@ type Attachments struct {
ImageSandwich ImageSandwich `json:"image-sandwich"` ImageSandwich ImageSandwich `json:"image-sandwich"`
ImageCoffee ImageCoffee `json:"image-coffee"` ImageCoffee ImageCoffee `json:"image-coffee"`
} }
type Image struct {
PostTitle string `json:"post_title"`
File string `json:"file"`
}
type Options struct { type Options struct {
ShowOnFront string `json:"show_on_front"` ShowOnFront string `json:"show_on_front"`
PageOnFront string `json:"page_on_front"` PageOnFront string `json:"page_on_front"`
@ -57,25 +56,94 @@ type ThemeMods struct {
Panel3 string `json:"panel_3"` Panel3 string `json:"panel_3"`
Panel4 string `json:"panel_4"` Panel4 string `json:"panel_4"`
} }
type Top struct { type Menus struct {
Name string `json:"name"`
Items []string `json:"items"`
}
type Social struct {
Name string `json:"name"` Name string `json:"name"`
Items []string `json:"items"` Items []string `json:"items"`
} }
type NavMenus struct { type NavMenus struct {
Top Top `json:"top"` Top Menus `json:"top"`
Social Social `json:"social"` Social Menus `json:"social"`
} }
type StarterContent struct { type StarterContent struct {
Widgets Widgets `json:"widgets"` Widgets Widgets `json:"widgets"`
Posts Posts `json:"posts"` Posts map[string]map[string]string `json:"posts"`
Attachments Attachments `json:"attachments"` Attachments map[string]Image `json:"attachments"`
Options Options `json:"options"` Options Options `json:"options"`
ThemeMods ThemeMods `json:"theme_mods"` ThemeMods ThemeMods `json:"theme_mods"`
NavMenus NavMenus `json:"nav_menus"` NavMenus NavMenus `json:"nav_menus"`
} }
var themesupport themeSupport var themesupport = themeSupport{
CustomLineHeight: true,
StarterContent: StarterContent{
Widgets: Widgets{
Sidebar1: []string{"text_business_info", "search", "text_about"},
Sidebar2: []string{"text_business_info"},
Sidebar3: []string{"text_about", "search"},
},
Posts: map[string]map[string]string{
"0": {
"home": "home",
},
"about": {
"thumbnail": "{{image-sandwich}}",
},
"contact": {
"thumbnail": "{{image-espresso}}",
},
"blog": {
"thumbnail": "{{image-coffee}}",
},
"homepage-section": {
"thumbnail": "{{image-espresso}}",
},
},
Attachments: map[string]Image{
"image-espresso": {
PostTitle: "浓缩咖啡",
File: "assets/images/espresso.jpg",
},
"image-sandwich": {
PostTitle: "三明治",
File: "assets/images/sandwich.jpg",
},
"image-coffee": {
PostTitle: "咖啡",
File: "assets/images/coffee.jpg",
},
},
Options: Options{
ShowOnFront: "page",
PageOnFront: "{{home}}",
PageForPosts: "{{blog}}",
},
ThemeMods: ThemeMods{
Panel1: "{{homepage-section}}",
Panel2: "{{about}}",
Panel3: "{{blog}}",
Panel4: "{{contact}}",
},
NavMenus: NavMenus{
Top: Menus{
Name: "顶部菜单",
Items: []string{
"link_home",
"page_about",
"page_blog",
"page_contact",
},
},
Social: Menus{
Name: "社交网络链接菜单",
Items: []string{
"link_yelp",
"link_facebook",
"link_twitter",
"link_instagram",
"link_email",
},
},
},
},
}

View File

@ -1,134 +0,0 @@
{
"core-block-patterns": true,
"widgets-block-editor": true,
"automatic-feed-links": true,
"title-tag": true,
"custom-line-height": true,
"post-thumbnails": true,
"menus": true,
"html5": [
"comment-form",
"comment-list",
"gallery",
"caption",
"script",
"style",
"navigation-widgets"
],
"post-formats": [
"aside",
"image",
"video",
"quote",
"link",
"gallery",
"audio"
],
"custom-logo": {
"width": 250,
"height": 250,
"flex-width": true,
"flex-height": false,
"header-text": "",
"unlink-homepage-logo": false
},
"customize-selective-refresh-widgets": true,
"editor-style": true,
"editor-styles": true,
"wp-block-styles": true,
"responsive-embeds": true,
"starter-content": {
"widgets": {
"sidebar-1": [
"text_business_info",
"search",
"text_about"
],
"sidebar-2": [
"text_business_info"
],
"sidebar-3": [
"text_about",
"search"
]
},
"posts": {
"0": "home",
"about": {
"thumbnail": "{{image-sandwich}}"
},
"contact": {
"thumbnail": "{{image-espresso}}"
},
"blog": {
"thumbnail": "{{image-coffee}}"
},
"homepage-section": {
"thumbnail": "{{image-espresso}}"
}
},
"attachments": {
"image-espresso": {
"post_title": "浓缩咖啡",
"file": "assets\/images\/espresso.jpg"
},
"image-sandwich": {
"post_title": "三明治",
"file": "assets\/images\/sandwich.jpg"
},
"image-coffee": {
"post_title": "咖啡",
"file": "assets\/images\/coffee.jpg"
}
},
"options": {
"show_on_front": "page",
"page_on_front": "{{home}}",
"page_for_posts": "{{blog}}"
},
"theme_mods": {
"panel_1": "{{homepage-section}}",
"panel_2": "{{about}}",
"panel_3": "{{blog}}",
"panel_4": "{{contact}}"
},
"nav_menus": {
"top": {
"name": "顶部菜单",
"items": [
"link_home",
"page_about",
"page_blog",
"page_contact"
]
},
"social": {
"name": "社交网络链接菜单",
"items": [
"link_yelp",
"link_facebook",
"link_twitter",
"link_instagram",
"link_email"
]
}
}
},
"custom-header": {
"default-image": "http:\/\/wp.test\/wp-content\/themes\/twentyseventeen\/assets\/images\/header.jpg",
"random-default": false,
"width": 2000,
"height": 1200,
"flex-height": true,
"flex-width": false,
"default-text-color": "",
"header-text": true,
"uploads": true,
"wp-head-callback": "twentyseventeen_header_style",
"admin-head-callback": "",
"admin-preview-callback": "",
"video": true,
"video-active-callback": "is_front_page"
},
"widgets": true
}

View File

@ -1,8 +1,6 @@
package twentyseventeen package twentyseventeen
import ( import (
"embed"
"encoding/json"
"fmt" "fmt"
"github.com/fthvgb1/wp-go/app/cmd/reload" "github.com/fthvgb1/wp-go/app/cmd/reload"
"github.com/fthvgb1/wp-go/app/pkg/config" "github.com/fthvgb1/wp-go/app/pkg/config"
@ -11,7 +9,6 @@ import (
"github.com/fthvgb1/wp-go/app/pkg/logs" "github.com/fthvgb1/wp-go/app/pkg/logs"
"github.com/fthvgb1/wp-go/app/pkg/models" "github.com/fthvgb1/wp-go/app/pkg/models"
"github.com/fthvgb1/wp-go/app/plugins" "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"
"github.com/fthvgb1/wp-go/app/theme/wp/components" "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/theme/wp/components/widget"
@ -24,14 +21,6 @@ import (
const ThemeName = "twentyseventeen" const ThemeName = "twentyseventeen"
func Init(fs embed.FS) {
b, err := fs.ReadFile(str.Join(ThemeName, "/themesupport.json"))
if err != nil {
return
}
err = json.Unmarshal(b, &themesupport)
}
var paginate = func() plugins.PageEle { var paginate = func() plugins.PageEle {
p := plugins.TwentyFifteenPagination() p := plugins.TwentyFifteenPagination()
p.PrevEle = `<a class="prev page-numbers" href="%s"><svg class="icon icon-arrow-left" aria-hidden="true" role="img"> <use href="#icon-arrow-left" xlink:href="#icon-arrow-left"></use> </svg> p.PrevEle = `<a class="prev page-numbers" href="%s"><svg class="icon icon-arrow-left" aria-hidden="true" role="img"> <use href="#icon-arrow-left" xlink:href="#icon-arrow-left"></use> </svg>
@ -48,7 +37,6 @@ func Hook(h *wp.Handle) {
func configs(h *wp.Handle) { func configs(h *wp.Handle) {
conf := config.GetConfig() conf := config.GetConfig()
wphandle.UsePlugins(h)
wp.InitPipe(h) wp.InitPipe(h)
h.PushHandler(constraints.PipeMiddleware, constraints.Home, h.PushHandler(constraints.PipeMiddleware, constraints.Home,
wp.NewHandleFn(widget.IsCategory, 100, "widget.IsCategory")) wp.NewHandleFn(widget.IsCategory, 100, "widget.IsCategory"))

View File

@ -240,7 +240,6 @@ func IsCategory(h *wp.Handle) {
if ok { if ok {
h.C.Redirect(http.StatusMovedPermanently, fmt.Sprintf("/p/category/%s", name)) h.C.Redirect(http.StatusMovedPermanently, fmt.Sprintf("/p/category/%s", name))
h.Abort() h.Abort()
h.StopPipe()
} }
} }

View File

@ -4,6 +4,7 @@ import (
"github.com/fthvgb1/wp-go/app/cmd/reload" "github.com/fthvgb1/wp-go/app/cmd/reload"
"github.com/fthvgb1/wp-go/app/pkg/constraints" "github.com/fthvgb1/wp-go/app/pkg/constraints"
"github.com/fthvgb1/wp-go/app/pkg/logs" "github.com/fthvgb1/wp-go/app/pkg/logs"
"github.com/fthvgb1/wp-go/app/plugins/wphandle/apply"
"github.com/fthvgb1/wp-go/app/wpconfig" "github.com/fthvgb1/wp-go/app/wpconfig"
"github.com/fthvgb1/wp-go/helper/maps" "github.com/fthvgb1/wp-go/helper/maps"
str "github.com/fthvgb1/wp-go/helper/strings" str "github.com/fthvgb1/wp-go/helper/strings"
@ -100,6 +101,11 @@ func InitHandle(fn func(*Handle), h *Handle) {
h.ginH = gin.H{} h.ginH = gin.H{}
fnMap = map[string]map[string]any{} fnMap = map[string]map[string]any{}
fnHook = map[string]map[string]any{} fnHook = map[string]map[string]any{}
v := apply.UsePlugins()
pluginFn, ok := v.(func(*Handle))
if ok {
pluginFn(h)
}
fn(h) fn(h)
h.C.Set("inited", true) h.C.Set("inited", true)
inited = true inited = true
@ -126,10 +132,14 @@ func InitHandle(fn func(*Handle), h *Handle) {
func (h *Handle) Abort() { func (h *Handle) Abort() {
h.abort = true h.abort = true
h.stopPipe = true
} }
func (h *Handle) StopPipe() { func (h *Handle) StopPipe() {
h.stopPipe = true h.stopPipe = true
} }
func (h *Handle) StopHandle() {
h.abort = true
}
func (h *Handle) CommonThemeMods() wpconfig.ThemeMods { func (h *Handle) CommonThemeMods() wpconfig.ThemeMods {
return h.themeMods return h.themeMods
@ -214,7 +224,6 @@ func (h *Handle) RenderHtml(t *template.Template, statsCode int, name string) {
h.C.Status(statsCode) h.C.Status(statsCode)
err := t.ExecuteTemplate(h.C.Writer, name, h.ginH) err := t.ExecuteTemplate(h.C.Writer, name, h.ginH)
h.Abort() h.Abort()
h.StopPipe()
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -235,12 +244,12 @@ func (h *Handle) CommonComponents() {
func PreRenderTemplate(h *Handle) { func PreRenderTemplate(h *Handle) {
h.C.HTML(h.Code, h.templ, h.ginH) h.C.HTML(h.Code, h.templ, h.ginH)
h.Abort() h.Abort()
h.StopPipe()
} }
func NewHandleFn(fn HandleFn[*Handle], order int, name string) HandleCall { func NewHandleFn(fn HandleFn[*Handle], order int, name string) HandleCall {
return HandleCall{Fn: fn, Order: order, Name: name} return HandleCall{Fn: fn, Order: order, Name: name}
} }
func NothingToDo(*Handle) { func NothingToDo(h *Handle) {
h.Abort()
} }