commit fd37a4aa86a2a768b7501d548c87a6a58481a2cf parent 9f360369e1aacb9201cf2c0a57c20734b1c27ad1 Author: Daniel Barlow <dan@telent.net> Date: Wed, 23 Jul 2025 17:32:00 +0100 extract send-post fn and use it for yy/mm pages Diffstat:
| M | main.fnl | | | 77 | +++++++++++++++++++++++++++++++++++++++++++---------------------------------- |
1 file changed, 43 insertions(+), 34 deletions(-)
diff --git a/main.fnl b/main.fnl @@ -105,7 +105,6 @@ title))) (fn post-header [post stream] - (page-header stream post.title) (stream:write_chunk (string.format "<div class=\"entry\"> @@ -167,16 +166,37 @@ in the Fediverse at <a href=\"https://axillae.telent.net/\">@dan@axillae.telent. (define-tests :sidebar (print (view (all-months post-index)))) +(fn send-post [post stream] + (let [path (. post :full-path)] + (print :path path) + (with-open [f (io.open path )] + (when f + (f:seek :set post.body-offset) + (post-header post stream) + (if (string.match path "%.textile$") + (let [s { :write #(stream:write_chunk $2) } ] + (each [_ el (ipairs (textile.parse f))] + (textile.to-html s el))) + (stream:write_chunk + (lcmark.convert (f:read "*a") "html" { :yaml_parser #($1) }) + false) + ))))) + + (fn search-posts [route stream] (server.headers stream { }) (page-header stream "Recently") (stream:write_chunk "<p><ul>") (each [slug post (pairs (post-index:search route))] - (stream:write_chunk - (string.format - "<li><a href=%q>%s</a></li>" - slug - (or post.title post.subject)))) + (case route.format + :html + (send-post post stream) + _ + (stream:write_chunk + (string.format + "<li><a href=%q>%s</a></li>" + slug + post.title)))) (stream:write_chunk "</ul>" ) (sidebar post-index stream) (page-footer stream) @@ -184,34 +204,23 @@ in the Fediverse at <a href=\"https://axillae.telent.net/\">@dan@axillae.telent. (fn dispatch [route stream] - (let [s { :write #(stream:write_chunk $2) } ] - (case route.command - :show - (let [post (post-index:get route.slug) - path (. post :full-path)] - (print :path path) - (server.headers stream { }) - (with-open [f (io.open path )] - (when f - (f:seek :set post.body-offset) - (post-header post stream) - (if (string.match path "%.textile$") - (each [_ el (ipairs (textile.parse f))] - (textile.to-html s el)) - (stream:write_chunk - (lcmark.convert (f:read "*a") "html" { :yaml_parser #($1) }) - false) - ))) - (sidebar post-index stream) - (page-footer stream) - (stream:write_chunk "" true)) - :sendfile - (with-open [f (io.open route.pathname :r)] - (server.headers stream { :content-type (content-type-for-path route.pathname) }) - (stream:write_body_from_file f)) - :search - (search-posts route stream) - ))) + (case route.command + :show + (let [post (post-index:get route.slug) + path (. post :full-path)] + (server.headers stream { }) + (page-header stream post.title) + (send-post post stream) + (sidebar post-index stream) + (page-footer stream) + (stream:write_chunk "" true)) + :sendfile + (with-open [f (io.open route.pathname :r)] + (server.headers stream { :content-type (content-type-for-path route.pathname) }) + (stream:write_body_from_file f)) + :search + (search-posts route stream) + )) (fn http-handler [_ stream] (let [req-headers (assert (stream:get_headers))