Commit 5a26b765 authored by Steven's avatar Steven

chore: add memo content snippet

parent 0053977b
...@@ -8,6 +8,7 @@ import ( ...@@ -8,6 +8,7 @@ import (
"log/slog" "log/slog"
"slices" "slices"
"time" "time"
"unicode/utf8"
"github.com/google/cel-go/cel" "github.com/google/cel-go/cel"
"github.com/lithammer/shortuuid/v4" "github.com/lithammer/shortuuid/v4"
...@@ -1301,5 +1302,27 @@ func getMemoContentSnippet(content string) (string, error) { ...@@ -1301,5 +1302,27 @@ func getMemoContentSnippet(content string) (string, error) {
} }
plainText := renderer.NewStringRenderer().Render(nodes) plainText := renderer.NewStringRenderer().Render(nodes)
if len(plainText) > 100 {
return substring(plainText, 100) + "...", nil
}
return plainText, nil return plainText, nil
} }
func substring(s string, length int) string {
if length <= 0 {
return ""
}
runeCount := 0
byteIndex := 0
for byteIndex < len(s) {
_, size := utf8.DecodeRuneInString(s[byteIndex:])
byteIndex += size
runeCount++
if runeCount == length {
break
}
}
return s[:byteIndex]
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment