Just moved the blog from coleslaw to zora. Here are a couple scripts I used to convert things along the way!

Converting the tags from comma-separated to toml


#!/usr/bin/sbcl --script

(require 'uiop)

(defun string-split (separator string)
  (unless (zerop (length string))
    (loop for start = 0 then end
          for end = (position separator string :start (1+ start) :test #'char=)

          collecting (subseq string
                             (if (zerop start)
                                 (1+ start))
          while end)))

(defun tags-line-p (line)
  (and (>= (length line) 5)
       (string= "tags:" line :end2 5)))

(defun mangle-tags-line (line stream)
  (flet ((trim-space (string)
           (string-trim '(#\Space) string)))

    (let* ((rest-of-line (trim-space (subseq line (length "tags:"))))
           (tags (mapcar #'trim-space (string-split #\, rest-of-line))))

      (format stream "tags = [~%~{  ~S,~%~}]~%" tags))))

(defun mangle-file (filename &key (dry-run-p t))
  (uiop:with-temporary-file (:stream out-stream
                             :pathname temp-file
                             :keep dry-run-p)
    (format t "~&Processing ~a into ~a.~%" filename temp-file)

    (with-open-file (in-stream filename)
      (loop for line = (read-line in-stream nil nil)
            while line

            if (tags-line-p line)
              do (mangle-tags-line line out-stream)
              do (write-line line out-stream)))

    (unless dry-run-p
      (format t "~&Finished magling.  Copying ~a to ~a.~%" temp-file filename)
      (uiop:copy-file temp-file filename)
      #+nil(uiop:rename-file-overwriting-target temp-file filename))))

(if (>= (length *posix-argv*) 2)
    (mangle-file (merge-pathnames (second *posix-argv*))
                 :dry-run-p nil)
      (format t "~&No file specified~%")
      (uiop:quit 1)))

Converting from --- to +++.

gawk -i inplace '{if ($0 == "---") { print "+++" } else { print $0 }}' *.md

Adding the taxonomies tag before tags:

gawk -i inplace '{if ($1 == "tags" && a != "[taxonomies]") { print "[taxonomies]"; print $0} else { print $0 }} { a =$0 }' *.md