From 14f718834fa12d87a9abf419a05e7762b00c3b09 Mon Sep 17 00:00:00 2001 From: nathan Date: Sat, 24 May 2025 00:26:37 -0600 Subject: More small pointless changes --- org/blog/generate-html.scm | 71 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100755 org/blog/generate-html.scm (limited to 'org/blog/generate-html.scm') diff --git a/org/blog/generate-html.scm b/org/blog/generate-html.scm new file mode 100755 index 0000000..c214ff1 --- /dev/null +++ b/org/blog/generate-html.scm @@ -0,0 +1,71 @@ +#! /usr/bin/guile \ +-e main -s +!# + +(use-modules (sxml simple)) + +;; Loads an entire text file into a string +(define (read-entire-file file) + (call-with-input-file file + (lambda (fp) + (letrec ((read-characters + (lambda (fp) + (let ((character (read-char fp))) + (cond + ((eof-object? character) "") + (else (string-append (string character) + (read-characters fp)))))))) + (read-characters fp))))) + +;; Make a link for the article +(define (make-article-list-link article) + (let ((title (cadr (list-ref article 0))) + (name (cadr (list-ref article 2)))) + (string-append "
  • " title "
  • \n"))) + +;; Reads the article file and formats some stuff out +(define (get-raw-article file) + (letrec ((article (read-entire-file file)) + (article-open (string-contains article "
    ")) + (article-close (string-contains article "
    "))) + (substring article (+ article-open 9) article-close))) + +;; Makes a card for the article +(define (make-article-card article) + (let ((title (cadr (list-ref article 0))) + (name (cadr (list-ref article 2))) + (pub-date (cadr (list-ref article 4))) + (file (cadr (list-ref article 6)))) + (string-append + "\n\n" + " \n" + " \n" + "

    " title "

    --- " pub-date + "
    " (get-raw-article file) "
    \n"))) + +;; Generates a html blog from xml data +(define (generate-html) + (let ((template (read-entire-file "template.xhtml")) + (article-list "\n")) + (format #t template article-list article-cards))) + +(define (main args) + (generate-html)) -- cgit v1.2.3