limit display length of paste titles

This commit is contained in:
Stephen Chang 2014-11-21 13:57:32 -05:00
parent c6bbec5ffc
commit cf51352a69
2 changed files with 15 additions and 2 deletions

View File

@ -24,4 +24,13 @@
(define (mk-link url txt) `(a ((href ,url)) ,txt))
;; stx utils
(define (stx->string stx) (to-string/s (syntax->datum stx)))
(define (stx->string stx) (to-string/s (syntax->datum stx)))
;; string-truncate : String -> String
;; Truncates the given str to len-limit chars,
;; or returns str unchanged if its length is <= len-limit
(define (string-truncate str len-limit)
(if (<= (string-length str) len-limit)
str
(substring str 0 len-limit)))

View File

@ -28,6 +28,8 @@
(define scrbl-exe "/home/stchang/racket611/bin/scribble")
(define PASTE-TITLE-DISPLAY-LEN 32) ; limit length of displayed title
(define (mk-paste-url paste-num) (++ paste-url-base paste-num))
;(define (mk-link url txt) `(a ((href ,url)) ,txt))
@ -363,8 +365,10 @@
(with-redis-connection
(for/list ([pnum recent-pastes] #:when pnum)
(define name (HGET/str pnum 'name))
(define trunc-name
(string-truncate name PASTE-TITLE-DISPLAY-LEN))
`(tr (td ,(mk-link (mk-paste-url pnum) pnum))
(td ((style "width:1px"))) (td ,name)))))))
(td ((style "width:1px"))) (td ,trunc-name)))))))
;; middle ------------------------------------------------------------
(div ((style ,(~~ "position:absolute;left:14em;top:2em")))
(center