summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeonardo Bishop <me@leonardobishop.net>2025-09-18 21:06:30 +0100
committerLeonardo Bishop <me@leonardobishop.net>2025-09-18 21:06:30 +0100
commit75c7bb891851709ce2d43c2fee1774d00cbae86b (patch)
treef9716d216f129cf547018b74e93915a041d94ac0
parent9e779891fa91f44a9734b79ccb4f6aef48a0de3f (diff)
Truncate descriptions which are too longHEADmaster
-rw-r--r--pkg/html/service.go10
1 files changed, 9 insertions, 1 deletions
diff --git a/pkg/html/service.go b/pkg/html/service.go
index bead902..42351fb 100644
--- a/pkg/html/service.go
+++ b/pkg/html/service.go
@@ -1,6 +1,7 @@
package html
import (
+ "strings"
"time"
"git.leonardobishop.net/stash/pkg/entries"
@@ -51,7 +52,7 @@ func (s *service) GenerateHtml(entries []entries.EntryRow) (string, error) {
}
str += "</a>"
- str += "<span class=\"entry-description\">" + entry.Description + "</span>"
+ str += "<span class=\"entry-description\">" + truncateText(entry.Description, 300) + "</span>"
str += "<i class=\"entry-date\">on " + date.Format("02 Jan 2006") + "</i>"
str += "</span>"
}
@@ -62,3 +63,10 @@ func (s *service) GenerateHtml(entries []entries.EntryRow) (string, error) {
return str, nil
}
+
+func truncateText(s string, max int) string {
+ if max > len(s) {
+ return s
+ }
+ return s[:strings.LastIndex(s[:max], " ")] + "..."
+}