commit 719863bbe008aad642fb3bf314f4ee03e38c6adb
parent e5e3c787a86c5a21c13802f9606c9b84b7c7a0ac
Author: Daniel Barlow <dan@telent.net>
Date: Wed, 23 Jul 2025 21:42:04 +0100
implement excerpts
we can choose to display only the first ~ 500 chars from each post
Diffstat:
| M | main.fnl | | | 41 | +++++++++++++++++++---------------------- |
1 file changed, 19 insertions(+), 22 deletions(-)
diff --git a/main.fnl b/main.fnl
@@ -15,7 +15,7 @@
#(if (= $2 "/")
{
:command :search
- :format :summaries
+ :format :posts
:filter nil
:order {:date :descending}
:offset 0
@@ -32,7 +32,7 @@
}))
#(case (string.match $2 "/(%d+)/(%d+)/([%w_]+)" 1)
- (year month slug) { :command :show :format :html : slug })
+ (year month slug) { :command :show : slug })
#(case (string.match $2 "/(%d+)/(%d+)/" 1)
(year month)
@@ -40,14 +40,14 @@
before (os.time {: year :month (+ month 1) :day 2 })]
{
:command :search
- :format :html
+ :format :posts
:filter {:older before :newer after}
:order {:date :ascending}
:offset 0
}))
#(case (string.match $2 "/([%w_]+)$" 1)
- slug { :command :show :format :html : slug })
+ slug { :command :show : slug })
])
@@ -61,7 +61,7 @@
(expect= (route-request :get "/")
{
:command :search
- :format :summaries
+ :format :posts
:filter nil
:order {:date :descending}
:offset 0
@@ -71,14 +71,13 @@
(expect= (route-request :get "/pagename")
{
:command :show
- :format :html
:slug "pagename"
})
(expect= (route-request :get "/2004/7/")
{
:command :search
- :format :html
+ :format :posts
:filter {:newer 1088420400 :older 1091444400}
:order {:date :ascending}
:offset 0
@@ -168,21 +167,23 @@ 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)]
+(fn send-post [post stream excerpt?]
+ (let [path (. post :full-path)
+ s { :write #(stream:write_chunk $2) } ]
(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)))
+ (each [_ el (ipairs (textile.parse f))
+ &until (and excerpt? (> (f:seek :cur 0) 500))]
+ (textile.to-html s el))
(stream:write_chunk
- (lcmark.convert (f:read "*a") "html" { :yaml_parser #($1) })
- false)
- )))))
+ (lcmark.convert (f:read (if excerpt? 600 "*a")) "html" { :yaml_parser #($1) })
+ false))
+ (when (and excerpt? (= (f:read 0) ""))
+ (textile.to-html s [[:div {:class :continuelink}] [:div [[:a { :href post.url-path}] "... continue reading"]]]))))))
(fn search-posts [route stream]
@@ -191,14 +192,10 @@ in the Fediverse at <a href=\"https://axillae.telent.net/\">@dan@axillae.telent.
(stream:write_chunk "<p><ul>")
(each [_ post (pairs (post-index:search route))]
(case route.format
- :html
+ :posts
(send-post post stream)
- _
- (stream:write_chunk
- (string.format
- "<li><a href=%q>%s</a></li>"
- post.url-path
- post.title))))
+ :excerpts
+ (send-post post stream true)))
(stream:write_chunk "</ul>" )
(sidebar post-index stream)
(page-footer stream)