package plugins import ( "fmt" "github.com/gin-gonic/gin" "github/fthvgb1/wp-go/cache" "github/fthvgb1/wp-go/helper" "github/fthvgb1/wp-go/models" "github/fthvgb1/wp-go/vars" "regexp" "strings" "time" "unicode/utf8" ) var removeWpBlock = regexp.MustCompile("") var more = regexp.MustCompile("") var digestCache *cache.MapCache[uint64, string] var quto = regexp.MustCompile(`" *|& *|< *|> ?|  *`) func InitDigestCache() { digestCache = cache.NewMapCache[uint64](digestRaw, vars.Conf.DigestCacheTime) } func digestRaw(arg ...any) (string, error) { str := arg[0].(string) id := arg[1].(uint64) limit := vars.Conf.DigestWordCount if limit < 0 { return str, nil } else if limit == 0 { return "", nil } return DigestRaw(str, limit, id), nil } func DigestCache(ctx *gin.Context, id uint64, str string) string { content, _ := digestCache.GetCache(ctx, id, time.Second, str, id) return content } func DigestRaw(str string, limit int, id uint64) string { if r := more.FindString(str); r != "" { m := strings.Split(str, r) str = m[0] return "" } content := removeWpBlock.ReplaceAllString(str, "") content = strings.Trim(content, " \t\n\r\000\x0B") content = strings.Replace(content, "]]>", "]]>", -1) content = helper.StripTagsX(content, "