diff options
Diffstat (limited to 'haunt/jakob/utils.scm')
| -rw-r--r-- | haunt/jakob/utils.scm | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/haunt/jakob/utils.scm b/haunt/jakob/utils.scm index a41d21a..a104510 100644 --- a/haunt/jakob/utils.scm +++ b/haunt/jakob/utils.scm @@ -24,7 +24,9 @@ date->string* intersperse first-paragraph - description-from-post)) + description-from-post + + elide-string)) (define (maybe-list . args) "Create a list of all ARGS that are neither #f nor unspecified." @@ -93,3 +95,12 @@ is of an odd length and every second element is DELIM." (let* ((sxml (first-paragraph post)) (extracted (collect-strings (first-elem sxml) (list)))) (string-join (map string-trim-both (reverse extracted)) " "))) + +(define (elide-string s len) + "Return S elided to be at most LEN characters" + (when (< len 3) (error "LEN cannot be smaller than 3")) + (if (<= (string-length s) len) + s + (string-append (string-take s (floor/ (- len 3) 2)) + "..." + (string-take-right s (ceiling/ (- len 3) 2))))) |