summaryrefslogtreecommitdiffstats
path: root/feed.scm
diff options
context:
space:
mode:
authorJan Tuomi <jan@jantuomi.fi>2024-04-22 21:58:10 +0300
committerJan Tuomi <jan@jantuomi.fi>2024-04-22 21:58:10 +0300
commite3b21ffd6b88008fd1cc3599a0f816773dc11f9d (patch)
tree6843abb968954cce59e43ebf606bda2ab39b2692 /feed.scm
parentd369f1411c8cf0a07686ed944c8f9f98521129fd (diff)
Refactor whole thing to use in-memory DB as source of truth
Diffstat (limited to 'feed.scm')
-rw-r--r--feed.scm92
1 files changed, 3 insertions, 89 deletions
diff --git a/feed.scm b/feed.scm
index c90bd11..8fd88bf 100644
--- a/feed.scm
+++ b/feed.scm
@@ -10,96 +10,10 @@
(chicken sort)
srfi-1
srfi-13
- utils)
- (define (generate-feed src-dir archive-subdir out-dir)
- (define archive-dir (make-pathname src-dir archive-subdir))
- (define paths (glob (format "~A/*" archive-dir)))
- (define link-format (format "~A/%s" archive-subdir))
- (define output-port
- (process "vendor/bin/pandoc-rss"
- (apply list "-s"
- "-t" "jan's garden"
- "-d" "RSS feed for Jan's personal digital garden"
- "-l" "https://jan.systems"
- "-f" link-format
- "-n" "en-GB"
- "-c" "CC BY-SA 4.0"
- "-w" "https://jan.systems"
- paths)))
- (define output (read-string #f output-port))
- (define out-path (make-pathname out-dir "feed.xml"))
- (printf "[info] writing RSS feed to \"~A\"~%" out-path)
- (with-output-to-file out-path
- (λ () (print output))))
+ utils
+ md-parser
+ )
- (define (collect-fm-lines lines #!optional (acc '()))
- (if (string=? "---" (car lines))
- acc
- (collect-fm-lines (cdr lines) (cons (car lines) acc))))
- (define (extract-field field fm) (call/cc (@ extract-field* field fm)))
- (define (extract-field* field fm return)
- (define (search line)
- (define irx (format "^~A: (.+?)$" field))
- (define m (irregex-search irx line))
- (if m
- (return (submatch m))))
-
- (for-each search fm)
- #f)
-
- (define (read-md-frontmatter md-path)
- (define lines (with-input-from-file md-path
- (λ () (read-lines))))
-
- (define (inner return)
- (if (not (string=? "---" (car lines)))
- (return #f))
-
- (define fm (collect-fm-lines (cdr lines)))
- `((title . ,(extract-field "title" fm))
- (date . ,(extract-field "date" fm))
- (kind . ,(extract-field "kind" fm))))
-
- (call/cc (@ inner)))
-
- (define (generate-archive-index src-dir archive-subdir)
- (define archive-dir (make-pathname src-dir archive-subdir))
- (define paths (pipe (glob (format "~A/*" archive-dir))
- (@ filter (@ irregex-search "\\.md$"))))
-
- (define fm (map (λ (path) (cons path (read-md-frontmatter path))) paths))
- (for-each (@ printf "~A~%") fm)
- ;; newest first
- (define (less? a b)
- (string>? (assocdr 'date (cdr a)) (assocdr 'date (cdr b))))
-
- (define fm-sorted (sort fm less?))
-
- (define (to-li pair)
- (printf "[info] indexing page ~A~%" pair)
- (define path (car pair))
- (define title (assocdr 'title (cdr pair)))
- (define date (assocdr 'date (cdr pair)))
- (define kind (assocdr 'kind (cdr pair)))
- (define link (pipe path
- (@ replace (format "^~A\\/?" src-dir) "/")
- (@ replace "\\.md$" "")))
- (format "<li class=\"archive-entry\"><a href=\"~A\">~A</a><small><span>[~A]</span> (~A)</small></li>"
- link title kind date))
-
- (define index-lis (map to-li fm-sorted))
- (define out-md (string-append "---\n"
- "title: archive – jan's garden\n"
- "hide-body-title: defined\n"
- "---\n"
- "# Archive\n\n"
- "Follow via [RSS](/feed.xml) ([Huh?](https://aboutfeeds.com/))\n\n"
- (string-append "<ul class=\"archive-list\">"
- (string-join index-lis "\n")
- "</ul>")))
-
- (with-output-to-file (make-pathname archive-dir "index.md")
- (λ () (print out-md))))
)