From: Amin Bandali Date: Fri, 6 Dec 2019 17:49:23 +0000 (-0500) Subject: avoid repetition of post list table code X-Git-Url: https://git.shemshak.org/~bandali/bndl.org/commitdiff_plain/60a33c6fd471a16ac68a3f767b59def05f2f9832?ds=sidebyside avoid repetition of post list table code --- diff --git a/haunt.scm b/haunt.scm index 7b2d740..7948659 100644 --- a/haunt.scm +++ b/haunt.scm @@ -137,12 +137,25 @@ resulting list is of an odd length and every second element is DELIM." "https://man.sr.ht/lists.sr.ht/etiquette.md") "]") "."))) +(define* (post-uri site post #:optional prefix) + (string-append (or prefix "") "/" + (site-post-slug site post) ".html")) + +(define* (post-list-table site posts #:optional prefix) + `((table + (@ (class "post-list")) + (tbody + ,@(map + (lambda (post) + `(tr + (td ,(aa (post-ref post 'title) + (post-uri site post prefix))) + (td (small ,(date->string (post-date post) + my-date-format))))) + posts))))) + (define* (my-collection-template site title posts prefix #:optional all-posts tag) - (define (post-uri post) - (string-append (or prefix "") "/" - (site-post-slug site post) ".html")) - `((h2 ,title ,(if tag (aa `(img (@ (class "feed-icon-h2") @@ -150,16 +163,7 @@ resulting list is of an odd length and every second element is DELIM." (alt "subscribe to atom feed"))) (tag-uri my-tag-prefix tag ".xml")) '())) - (table - (@ (class "post-list")) - (tbody - ,@(map (lambda (post) - `(tr - (td ,(aa (post-ref post 'title) (post-uri post))) - (td (small - ,(date->string (post-date post) - my-date-format))))) - posts))) + ,(post-list-table site posts prefix) (h2 "Tags") ,(tag-links (or all-posts posts)) ,(if tag @@ -297,19 +301,7 @@ resulting list is of an odd length and every second element is DELIM." (src "/icon-12px.png") (alt "subscribe to rss feed"))) "RSS") "notes.rss") " feeds.") - (table - (@ (class "post-list")) - (tbody - ,@(map - (lambda (post) - (define (post-uri post) - (string-append "/" - (site-post-slug site post) ".html")) - `(tr - (td ,(aa (post-ref post 'title) (post-uri post))) - (td (small - ,(date->string (post-date post) my-date-format))))) - (take-up-to 10 (posts/reverse-chronological posts))))))) + ,(post-list-table site posts))) (define (index-page site posts) (make-page