Skip to content

armgit / memos

Public Imported from GitHub
0

Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.

chore: add memo content snippet

Steven5a26b7651176
diff --git a/server/router/api/v1/memo_service.go b/server/router/api/v1/memo_service.go
index bd8f94410..58db81948 100644
--- a/server/router/api/v1/memo_service.go
+++ b/server/router/api/v1/memo_service.go
@@ -8,6 +8,7 @@ import (
"log/slog"
"slices"
"time"
+ "unicode/utf8"
"github.com/google/cel-go/cel"
"github.com/lithammer/shortuuid/v4"
@@ -1301,5 +1302,27 @@ func getMemoContentSnippet(content string) (string, error) {
}
plainText := renderer.NewStringRenderer().Render(nodes)
+ if len(plainText) > 100 {
+ return substring(plainText, 100) + "...", 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]
+}