diff --git a/app/actions/themehook.go b/app/actions/themehook.go index d6f5300..f2c898c 100644 --- a/app/actions/themehook.go +++ b/app/actions/themehook.go @@ -8,7 +8,7 @@ import ( func ThemeHook(scene string) func(*gin.Context) { return func(c *gin.Context) { - t := theme.GetCurrentTemplateName() + t := theme.GetCurrentTheme() h := wp.NewHandle(c, scene, t) theme.Hook(t, h) } diff --git a/app/theme/hook.go b/app/theme/hook.go index 47914f6..b76cd59 100644 --- a/app/theme/hook.go +++ b/app/theme/hook.go @@ -8,10 +8,18 @@ import ( var themeMap = safety.NewMap[string, func(*wp.Handle)]() -func AddThemeHookFunc(name string, fn func(handle *wp.Handle)) { +func AddTheme(name string, fn func(handle *wp.Handle)) { themeMap.Store(name, fn) } +func DelTheme(name string) { + themeMap.Delete(name) +} + +func GetTheme(name string) (func(*wp.Handle), bool) { + return themeMap.Load(name) +} + func IsThemeHookFuncExist(name string) bool { _, ok := themeMap.Load(name) return ok diff --git a/app/theme/theme.go b/app/theme/theme.go index 03676f5..905550a 100644 --- a/app/theme/theme.go +++ b/app/theme/theme.go @@ -8,17 +8,17 @@ import ( ) func InitTheme() { - AddThemeHookFunc(twentyfifteen.ThemeName, twentyfifteen.Hook) - AddThemeHookFunc(twentyseventeen.ThemeName, twentyseventeen.Hook) + AddTheme(twentyfifteen.ThemeName, twentyfifteen.Hook) + AddTheme(twentyseventeen.ThemeName, twentyseventeen.Hook) } -func GetCurrentTemplateName() string { - templateName := config.GetConfig().Theme - if templateName == "" { - templateName = wpconfig.GetOption("template") +func GetCurrentTheme() string { + themeName := config.GetConfig().Theme + if themeName == "" { + themeName = wpconfig.GetOption("template") } - if !IsTemplateDirExists(templateName) { - templateName = "twentyfifteen" + if !IsTemplateDirExists(themeName) { + themeName = "twentyfifteen" } - return templateName + return themeName } diff --git a/go.mod b/go.mod index d251ef1..a6a7f16 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,8 @@ module github.com/fthvgb1/wp-go -go 1.20 +go 1.21.0 + +toolchain go1.23.0 require ( github.com/dlclark/regexp2 v1.11.4 @@ -16,14 +18,14 @@ require ( github.com/goccy/go-json v0.10.3 github.com/jmoiron/sqlx v1.4.0 golang.org/x/crypto v0.26.0 - golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa + golang.org/x/exp v0.0.0-20240823005443-9b4947da3948 gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df gopkg.in/yaml.v2 v2.4.0 ) require ( filippo.io/edwards25519 v1.1.0 // indirect - github.com/bytedance/sonic v1.12.1 // indirect + github.com/bytedance/sonic v1.12.2 // indirect github.com/bytedance/sonic/loader v0.2.0 // indirect github.com/cloudwego/base64x v0.1.4 // indirect github.com/cloudwego/iasm v0.2.0 // indirect @@ -38,7 +40,7 @@ require ( github.com/mattn/go-isatty v0.0.20 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect - github.com/pelletier/go-toml/v2 v2.2.2 // indirect + github.com/pelletier/go-toml/v2 v2.2.3 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.12 // indirect golang.org/x/arch v0.9.0 // indirect