diff --git a/internal/pkg/cache/cache.go b/internal/pkg/cache/cache.go index 2dc4de2..445446d 100644 --- a/internal/pkg/cache/cache.go +++ b/internal/pkg/cache/cache.go @@ -9,6 +9,7 @@ import ( "github.com/fthvgb1/wp-go/internal/pkg/dao" "github.com/fthvgb1/wp-go/internal/pkg/logs" "github.com/fthvgb1/wp-go/internal/pkg/models" + "github.com/fthvgb1/wp-go/safety" "sync" "time" ) @@ -47,6 +48,7 @@ func InitActionsCommonCache() { archivesCaches = &Arch{ mutex: &sync.Mutex{}, fn: dao.Archives, + data: *safety.NewVar([]models.PostArchive{}), } searchPostIdsCache = cachemanager.MapCacheBy[string](dao.SearchPostIds, c.CacheTime.SearchPostCacheTime) @@ -95,14 +97,15 @@ func Archives(ctx context.Context) (r []models.PostArchive) { } type Arch struct { - data []models.PostArchive + data safety.Var[[]models.PostArchive] mutex *sync.Mutex fn func(context.Context) ([]models.PostArchive, error) month time.Month } func (a *Arch) getArchiveCache(ctx context.Context) []models.PostArchive { - l := len(a.data) + data := a.data.Load() + l := len(data) m := time.Now().Month() if l > 0 && a.month != m || l < 1 { r, err := a.fn(ctx) @@ -113,9 +116,10 @@ func (a *Arch) getArchiveCache(ctx context.Context) []models.PostArchive { a.mutex.Lock() defer a.mutex.Unlock() a.month = m - a.data = r + a.data.Store(r) + data = r } - return a.data + return data } // CategoriesTags categories or tags diff --git a/internal/theme/wp/components/block/category.go b/internal/theme/wp/components/block/category.go index 5c88434..cc60412 100644 --- a/internal/theme/wp/components/block/category.go +++ b/internal/theme/wp/components/block/category.go @@ -100,6 +100,17 @@ func Category(h *wp.Handle, id string, blockParser ParserBlock) (func() string, if maps.GetAnyAnyValWithDefaults(conf, false, "showHierarchy") { conf["hierarchical"] = int64(1) } + + class := maps.GetAnyAnyValWithDefaults(conf, "", "className") + classes := strings.Split(class, " ") + classes = append(classes, "wp-block-categories") + if conf["dropdown"].(int64) == 1 { + classes = append(classes, "wp-block-categories-dropdown") + conf["className"] = strings.Join(classes, " ") + } else { + classes = append(classes, "wp-block-categories-list") + conf["className"] = strings.Join(classes, " ") + } return conf }) @@ -130,16 +141,9 @@ func category(h *wp.Handle, id string, counter number.Counter[int], args map[str var out = "" categories := cache.CategoriesTags(h.C, constraints2.Category) class := []string{"widget", "widget_block", "widget_categories"} - classx := maps.GetAnyAnyValWithDefaults(conf, "", "className") - classes := strings.Split(classx, " ") - classes = append(classes, "wp-block-categories") if conf["dropdown"].(int64) == 1 { - classes = append(classes, "wp-block-categories-dropdown") - conf["className"] = strings.Join(classes, " ") out = dropdown(h, categories, counter(), args, conf) } else { - classes = append(classes, "wp-block-categories-list") - conf["className"] = strings.Join(classes, " ") out = categoryUl(h, categories, conf) } before := fmt.Sprintf(args["{$before_widget}"], str.Join("block-", id), strings.Join(class, " ")) diff --git a/internal/theme/wp/components/widget/archive.go b/internal/theme/wp/components/widget/archive.go index dda8515..47eb1f2 100644 --- a/internal/theme/wp/components/widget/archive.go +++ b/internal/theme/wp/components/widget/archive.go @@ -57,6 +57,10 @@ func Archive(h *wp.Handle, id string) string { args = maps.FilterZeroMerge(archiveArgs, CommonArgs(), commonArgs, args) args["{$before_widget}"] = fmt.Sprintf(args["{$before_widget}"], str.Join("archives-", id), str.Join("widget widget_", "archive")) args["{$title}"] = str.Join(args["{$before_title}"], conf["title"].(string), args["{$after_title}"]) + if slice.IsContained(h.CommonThemeMods().ThemeSupport.HTML5, "navigation-widgets") { + args["{$nav}"] = fmt.Sprintf(`" + } return args }) @@ -109,10 +113,6 @@ func archiveDropDown(h *wp.Handle, conf map[any]any, args map[string]string, arc } func archiveUl(h *wp.Handle, conf map[any]any, args map[string]string, archives []models.PostArchive) string { - if slice.IsContained(h.CommonThemeMods().ThemeSupport.HTML5, "navigation-widgets") { - args["{$nav}"] = fmt.Sprintf(`" - } s := str.NewBuilder() s.WriteString(`