package plugins import ( "context" "fmt" "github.com/fthvgb1/wp-go/app/pkg/config" "github.com/fthvgb1/wp-go/app/pkg/models" "github.com/fthvgb1/wp-go/cache" "github.com/fthvgb1/wp-go/cache/cachemanager" "github.com/fthvgb1/wp-go/helper" "github.com/fthvgb1/wp-go/plugin/digest" "regexp" "strings" "time" "unicode/utf8" ) var digestCache *cache.MapCache[uint64, string] var more = regexp.MustCompile("") var removeWpBlock = regexp.MustCompile("") func InitDigestCache() { digestCache = cachemanager.NewMemoryMapCache(nil, digestRaw, config.GetConfig().CacheTime.DigestCacheTime, "digestPlugin", func() time.Duration { return config.GetConfig().CacheTime.DigestCacheTime }) } func RemoveWpBlock(s string) string { return removeWpBlock.ReplaceAllString(s, "") } func digestRaw(ctx context.Context, id uint64, arg ...any) (string, error) { s := arg[1].(string) limit := arg[3].(int) if limit < 0 { return s, nil } else if limit == 0 { return "", nil } s = more.ReplaceAllString(s, "") fn := helper.GetContextVal(ctx, "postMoreFn", PostsMore) return Digests(s, id, limit, fn), nil } func Digests(content string, id uint64, limit int, fn func(id uint64, content, closeTag string) string) string { closeTag := "" content = RemoveWpBlock(content) tag := config.GetConfig().DigestAllowTag if tag == "" { tag = "