diff options
author | dan <[email protected]> | 2023-03-10 21:03:01 -0500 |
---|---|---|
committer | dan <[email protected]> | 2023-03-10 21:03:01 -0500 |
commit | 7698a174d89cd9ff814c55a456b3444df9e439cd (patch) | |
tree | 16ef89b16a47e7631c15104540b555848150ad4f | |
parent | 8aedffe9286e895b4fdc3e8894cf9112b22f72c0 (diff) | |
download | 54-7698a174d89cd9ff814c55a456b3444df9e439cd.tar.gz 54-7698a174d89cd9ff814c55a456b3444df9e439cd.tar.bz2 54-7698a174d89cd9ff814c55a456b3444df9e439cd.zip |
feat: links in content display as clickable links
-rw-r--r-- | main.scm | 21 | ||||
-rw-r--r-- | style.css | 13 |
2 files changed, 32 insertions, 2 deletions
@@ -179,6 +179,23 @@ (define (get-opt opt opts) (find (cut equal? <> opt) opts)) +(define (content->sxml content) + (let ([r "(https://[^ ]*)"]) + (if (irregex-search r content) + (let* ([starts-with-link (= 0 (irregex-match-start-index (irregex-search r content)))] + [texts (map (cut list 'div '(@ [class "content-text"]) <>) (irregex-split r content))] + [links (map (lambda (x) `(a (@ [href ,x] [class "content-link"]) ,x)) (irregex-extract r content))]) + (define (go xs ys take-y?) + (cond + [(and (not (null-list? ys)) take-y?) + (cons (car ys) (go xs (cdr ys) #f))] + [(and (not (null-list? xs)) (not take-y?)) + (cons (car xs) (go (cdr xs) ys #t))] + [else '()] + )) + (go texts links starts-with-link)) + `(p ,content)))) + (define (post current-user p . opts) (let ([uri (post-path (id p))] [hide-comments-link (get-opt 'hide-comments-link opts)]) @@ -196,8 +213,8 @@ [style "max-width:100%;"] [loading "lazy"])) '()) - (p (@ [style "min-height:0.5em;white-space:pre-wrap;"]) ,(content p)) - (div [@ (class "post-info")] + (div (@ [class "content-container"]) ,(content->sxml (content p))) + (div (@ [class "post-info"]) (em "- " (a (@ [href ,(user-path (user p))]) ,(user p))) (span (@ [style "float:right;"]) ,(if hide-comments-link '() `(a (@ [href ,uri] [style "margin-right:2px;"]) @@ -195,3 +195,16 @@ textarea { width: 100%; } } + +.content-container { + min-height:0.5em; + white-space:pre-wrap; +} + +.content-link { + display: inline-block; +} + +.content-text { + display: inline-block; +} |