#!/bin/env -S sbcl --script (require "asdf") (defparameter *template-file* #p"templates/gemlog.gmi") (defparameter *directory* (merge-pathnames #p"gemlog/") ) (defparameter *output-file* (merge-pathnames #p"index.gmi" *directory*)) ; TODO: rewrite with loop ; Thanks to this site: https://chkno.net/join.html ; Really loved the implementation of those two functions ! (defun intersperse (thing list) "Put thing between each of the elements in list. (intersperse '|,| '(1 2 3)) => (1 |,| 2 |,| 3)" (rest (mapcan (lambda (x) (list thing x)) list))) (defun intersperse-string (delimiter list) "A convient bare-string output wrapper for intersperse" (apply #'concatenate 'string (intersperse delimiter list))) (defun pathname-to-title (path) (let* ((tokens (uiop:split-string (string-trim " " (pathname-name path)) :separator "-")) (date (uiop:reduce/strcat (intersperse "-" tokens) :start 0 :end 5)) (title (string-capitalize (uiop:reduce/strcat (intersperse " " (nthcdr 3 tokens)))))) (uiop:strcat date " - " title))) (with-open-file (out *output-file* :direction :output :if-exists :supersede) (with-open-file (template *template-file* :if-does-not-exist nil) (when template (loop for line = (read-line template nil) while line do (format out "~a~%" line)))) (let ((files (directory (make-pathname :name :wild :type :wild :defaults *directory*)))) (when files (mapcar #'(lambda (f) (format out "~a~%" (pathname-to-title f))) (remove-if #'(lambda (f) (equal *output-file* f)) files)))))