package plugins import ( "fmt" "github.com/gin-gonic/gin" "github/fthvgb1/wp-go/cache" "github/fthvgb1/wp-go/config" "github/fthvgb1/wp-go/helper" "github/fthvgb1/wp-go/models/wp" "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.NewMapCacheByFn[uint64](digestRaw, config.Conf.DigestCacheTime) } func ClearDigestCache() { digestCache.ClearExpired() } func digestRaw(arg ...any) (string, error) { str := arg[0].(string) id := arg[1].(uint64) limit := config.Conf.DigestWordCount if limit < 0 { return str, nil } else if limit == 0 { return "", nil } return DigestRaw(str, limit, fmt.Sprintf("/p/%d", id)), nil } func DigestCache(ctx *gin.Context, id uint64, str string) string { content, _ := digestCache.GetCache(ctx, id, time.Second, str, id) return content } func ClearHtml(str string) string { content := removeWpBlock.ReplaceAllString(str, "") content = strings.Trim(content, " \t\n\r\000\x0B") content = strings.Replace(content, "]]>", "]]>", -1) content = helper.StripTagsX(content, "