再优化reload机制
This commit is contained in:
parent
5ca1a2c592
commit
a18616f50f
|
@ -4,6 +4,15 @@ import "github.com/fthvgb1/wp-go/safety"
|
|||
|
||||
var calls []func()
|
||||
|
||||
var str = safety.NewMap[string, string]()
|
||||
|
||||
func GetStr(name string) (string, bool) {
|
||||
return str.Load(name)
|
||||
}
|
||||
func SetStr(name, val string) {
|
||||
str.Store(name, val)
|
||||
}
|
||||
|
||||
func Vars[T any](defaults T) *safety.Var[T] {
|
||||
ss := safety.NewVar(defaults)
|
||||
calls = append(calls, func() {
|
||||
|
@ -27,4 +36,5 @@ func Reload() {
|
|||
for _, call := range calls {
|
||||
call()
|
||||
}
|
||||
str.Flush()
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"github.com/fthvgb1/wp-go/helper/maps"
|
||||
"github.com/fthvgb1/wp-go/helper/slice"
|
||||
str "github.com/fthvgb1/wp-go/helper/strings"
|
||||
"github.com/fthvgb1/wp-go/internal/cmd/reload"
|
||||
"github.com/fthvgb1/wp-go/internal/pkg/config"
|
||||
"github.com/fthvgb1/wp-go/internal/pkg/constraints"
|
||||
"github.com/fthvgb1/wp-go/internal/pkg/logs"
|
||||
|
@ -53,6 +54,15 @@ func (h *Handle) GetPassword() {
|
|||
}
|
||||
}
|
||||
|
||||
func (h *Handle) AutoCal(name string, fn func() string) {
|
||||
v, ok := reload.GetStr(name)
|
||||
if !ok {
|
||||
v = fn()
|
||||
reload.SetStr(name, v)
|
||||
}
|
||||
h.GinH[name] = v
|
||||
}
|
||||
|
||||
func (i *IndexHandle) ExecListPagePlugin(m map[string]Plugin[models.Posts, *Handle], calls ...func(*models.Posts)) {
|
||||
|
||||
pluginConf := config.GetConfig().ListPagePlugins
|
||||
|
|
|
@ -3,13 +3,9 @@ package common
|
|||
import (
|
||||
"fmt"
|
||||
"github.com/fthvgb1/wp-go/helper/html"
|
||||
"github.com/fthvgb1/wp-go/internal/cmd/reload"
|
||||
"github.com/fthvgb1/wp-go/internal/pkg/cache"
|
||||
"github.com/fthvgb1/wp-go/internal/pkg/constraints"
|
||||
)
|
||||
|
||||
var css = reload.Vars(constraints.Defaults)
|
||||
|
||||
func (h *Handle) CalCustomCss() (r string) {
|
||||
if h.ThemeMods.CustomCssPostId < 1 {
|
||||
return
|
||||
|
@ -21,12 +17,3 @@ func (h *Handle) CalCustomCss() (r string) {
|
|||
r = fmt.Sprintf(`<style id="wp-custom-css">%s</style>`, html.StripTags(post.PostContent, ""))
|
||||
return
|
||||
}
|
||||
|
||||
func (h *Handle) CustomCss() {
|
||||
cs := css.Load()
|
||||
if cs == constraints.Defaults {
|
||||
cs = h.CalCustomCss()
|
||||
css.Store(cs)
|
||||
}
|
||||
h.GinH["customCss"] = cs
|
||||
}
|
||||
|
|
|
@ -4,14 +4,10 @@ import (
|
|||
"fmt"
|
||||
"github.com/fthvgb1/wp-go/helper/maps"
|
||||
str "github.com/fthvgb1/wp-go/helper/strings"
|
||||
"github.com/fthvgb1/wp-go/internal/cmd/reload"
|
||||
"github.com/fthvgb1/wp-go/internal/pkg/cache"
|
||||
"github.com/fthvgb1/wp-go/internal/pkg/constraints"
|
||||
"github.com/fthvgb1/wp-go/internal/wpconfig"
|
||||
)
|
||||
|
||||
var logo = reload.Vars(constraints.Defaults)
|
||||
|
||||
func (h *Handle) CalCustomLogo() (r string) {
|
||||
id := uint64(h.ThemeMods.CustomLogo)
|
||||
if id < 1 {
|
||||
|
@ -44,12 +40,3 @@ func (h *Handle) CalCustomLogo() (r string) {
|
|||
r = fmt.Sprintf(`<a href="%s" class="custom-logo-link" rel="home"%s>%s</a>`, "/", ` aria-current="page"`, r)
|
||||
return
|
||||
}
|
||||
|
||||
func (h *Handle) CustomLogo() {
|
||||
s := logo.Load()
|
||||
if s == constraints.Defaults {
|
||||
s = h.CalCustomLogo()
|
||||
logo.Store(s)
|
||||
}
|
||||
h.GinH["customLogo"] = s
|
||||
}
|
||||
|
|
|
@ -97,9 +97,10 @@ func (d *DetailHandle) Render() {
|
|||
if d.CommentRender == nil {
|
||||
d.CommentRender = plugins.CommentRender()
|
||||
}
|
||||
d.SiteIcon()
|
||||
d.CustomLogo()
|
||||
d.CustomCss()
|
||||
d.CalBodyClass()
|
||||
d.AutoCal("siteIcon", d.CalSiteIcon)
|
||||
d.AutoCal("customLogo", d.CalCustomLogo)
|
||||
d.AutoCal("customCss", d.CalCustomCss)
|
||||
d.RenderComment()
|
||||
d.CalBodyClass()
|
||||
if d.Templ == "" {
|
||||
|
|
|
@ -112,9 +112,9 @@ func (i *IndexHandle) Render() {
|
|||
i.PageEle = plugins.TwentyFifteenPagination()
|
||||
}
|
||||
i.Pagination()
|
||||
i.SiteIcon()
|
||||
i.CustomLogo()
|
||||
i.CustomCss()
|
||||
i.AutoCal("siteIcon", i.CalSiteIcon)
|
||||
i.AutoCal("customLogo", i.CalCustomLogo)
|
||||
i.AutoCal("customCss", i.CalCustomCss)
|
||||
i.CalBodyClass()
|
||||
if i.Templ == "" {
|
||||
i.Templ = fmt.Sprintf("%s/posts/index.gohtml", i.Theme)
|
||||
|
|
|
@ -4,14 +4,11 @@ import (
|
|||
"fmt"
|
||||
"github.com/fthvgb1/wp-go/helper/slice"
|
||||
str "github.com/fthvgb1/wp-go/helper/strings"
|
||||
"github.com/fthvgb1/wp-go/internal/cmd/reload"
|
||||
"github.com/fthvgb1/wp-go/internal/pkg/cache"
|
||||
"github.com/fthvgb1/wp-go/internal/pkg/constraints"
|
||||
"github.com/fthvgb1/wp-go/internal/wpconfig"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var icon = reload.Vars(constraints.Defaults)
|
||||
var sizes = []string{"site_icon-270", "site_icon-32", "site_icon-192", "site_icon-180"}
|
||||
|
||||
func (h *Handle) CalSiteIcon() (r string) {
|
||||
|
@ -42,12 +39,3 @@ func (h *Handle) CalSiteIcon() (r string) {
|
|||
r = strings.Join(size, "\n")
|
||||
return
|
||||
}
|
||||
|
||||
func (h *Handle) SiteIcon() {
|
||||
s := icon.Load()
|
||||
if s == constraints.Defaults {
|
||||
s = h.CalSiteIcon()
|
||||
icon.Store(s)
|
||||
}
|
||||
h.GinH["siteIcon"] = s
|
||||
}
|
||||
|
|
|
@ -3,24 +3,15 @@ package twentyfifteen
|
|||
import (
|
||||
"fmt"
|
||||
"github.com/fthvgb1/wp-go/helper/slice"
|
||||
"github.com/fthvgb1/wp-go/internal/cmd/reload"
|
||||
"github.com/fthvgb1/wp-go/internal/pkg/constraints"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var colorCss = reload.Vars("default")
|
||||
|
||||
func (h *handle) colorSchemeCss() {
|
||||
color := colorCss.Load()
|
||||
if color == constraints.Defaults {
|
||||
func (h *handle) colorSchemeCss() string {
|
||||
s := slice.Filter([]string{h.calColorSchemeCss(), h.calSidebarTextColorCss(), h.calHeaderBackgroundColorCss()}, func(s string) bool {
|
||||
return s != ""
|
||||
})
|
||||
color = fmt.Sprintf(`<style id='%s-inline-css'%s>\n%s\n</style>\n`, "twentyfifteen-style", "", strings.Join(s, "\n"))
|
||||
colorCss.Store(color)
|
||||
}
|
||||
h.IndexHandle.GinH["colorScheme"] = color
|
||||
return fmt.Sprintf(`<style id='%s-inline-css'%s>\n%s\n</style>\n`, "twentyfifteen-style", "", strings.Join(s, "\n"))
|
||||
}
|
||||
func (h *handle) calColorSchemeCss() (r string) {
|
||||
color := h.getColorScheme()
|
||||
|
|
|
@ -5,8 +5,6 @@ import (
|
|||
"github.com/fthvgb1/wp-go/helper"
|
||||
"github.com/fthvgb1/wp-go/helper/maps"
|
||||
str "github.com/fthvgb1/wp-go/helper/strings"
|
||||
"github.com/fthvgb1/wp-go/internal/cmd/reload"
|
||||
"github.com/fthvgb1/wp-go/internal/pkg/constraints"
|
||||
)
|
||||
|
||||
var postx = map[string]string{
|
||||
|
@ -31,17 +29,6 @@ var repeat = map[string]string{
|
|||
"no-repeat": "no-repeat",
|
||||
}
|
||||
|
||||
var background = reload.Vars(constraints.Defaults)
|
||||
|
||||
func (h *handle) CustomBackGround() {
|
||||
b := background.Load()
|
||||
if b == constraints.Defaults {
|
||||
b = h.CalCustomBackGround()
|
||||
background.Store(b)
|
||||
}
|
||||
h.IndexHandle.GinH["customBackground"] = b
|
||||
}
|
||||
|
||||
func (h *handle) CalCustomBackGround() (r string) {
|
||||
if h.IndexHandle.ThemeMods.BackgroundImage == "" && h.IndexHandle.ThemeMods.BackgroundColor == themesupport.CustomBackground.DefaultColor {
|
||||
return
|
||||
|
|
|
@ -37,14 +37,6 @@ func newHandle(iHandle *common.IndexHandle, dHandle *common.DetailHandle) *handl
|
|||
return &handle{iHandle, dHandle}
|
||||
}
|
||||
|
||||
type detailHandle struct {
|
||||
*common.DetailHandle
|
||||
}
|
||||
|
||||
func newDetailHandle(dHandle *common.DetailHandle) *detailHandle {
|
||||
return &detailHandle{DetailHandle: dHandle}
|
||||
}
|
||||
|
||||
func Hook(h *common.Handle) {
|
||||
h.WidgetAreaData()
|
||||
h.GetPassword()
|
||||
|
@ -58,14 +50,14 @@ func Hook(h *common.Handle) {
|
|||
|
||||
func (h *handle) Index() {
|
||||
h.CustomHeader()
|
||||
h.colorSchemeCss()
|
||||
h.CustomBackGround()
|
||||
h.IndexHandle.AutoCal("colorScheme", h.colorSchemeCss)
|
||||
h.IndexHandle.AutoCal("customBackground", h.CalCustomBackGround)
|
||||
h.Indexs()
|
||||
}
|
||||
|
||||
func (h *handle) Detail() {
|
||||
h.CustomHeader()
|
||||
h.colorSchemeCss()
|
||||
h.CustomBackGround()
|
||||
h.IndexHandle.AutoCal("colorScheme", h.colorSchemeCss)
|
||||
h.IndexHandle.AutoCal("customBackground", h.CalCustomBackGround)
|
||||
h.Details()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user