cripslock

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 6a00cdb30156d02b71351816a306153ec236bb43
parent 719863bbe008aad642fb3bf314f4ee03e38c6adb
Author: Daniel Barlow <dan@telent.net>
Date:   Sat, 26 Jul 2025 21:15:30 +0100

add [[slug]] syntax for internal links in markdown

Diffstat:
Mmain.fnl | 13++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/main.fnl b/main.fnl @@ -167,6 +167,17 @@ in the Fediverse at <a href=\"https://axillae.telent.net/\">@dan@axillae.telent. (define-tests :sidebar (print (view (all-months post-index)))) +(fn translate-markdown [md] + ;; lcmark/cmark doesn't have any extension points that allow us + ;; to add actual new syntax so we're just going to postprocess + (let [html (lcmark.convert md "html" { :yaml_parser #($1) })] + (string.gsub html "%[%[([%w_-]+)%]%]" + (fn [slug] + (string.format + "<a href=%q class=internal>%s</a>" + slug + (. (post-index:get slug) :title)))))) + (fn send-post [post stream excerpt?] (let [path (. post :full-path) s { :write #(stream:write_chunk $2) } ] @@ -180,7 +191,7 @@ in the Fediverse at <a href=\"https://axillae.telent.net/\">@dan@axillae.telent. &until (and excerpt? (> (f:seek :cur 0) 500))] (textile.to-html s el)) (stream:write_chunk - (lcmark.convert (f:read (if excerpt? 600 "*a")) "html" { :yaml_parser #($1) }) + (translate-markdown (f:read (if excerpt? 600 "*a"))) false)) (when (and excerpt? (= (f:read 0) "")) (textile.to-html s [[:div {:class :continuelink}] [:div [[:a { :href post.url-path}] "... continue reading"]]]))))))