mirror of github:amycatgirl/amycatgirl.github.io
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: fallback generation script written in common lisp

The script has a few dependencies (namely, quicklisp) that need to be
handled in a CI environment but otherwise it's pretty lightweight and
removes the emacs dependency.

closes #1 and partialy solves #2

Signed-off-by: Amy <amy+git@amogus.cloud>

Amy 794de9b2 9d15c74e

+39 -6
+39 -6
fallback.lisp
··· 4 4 5 5 (ql:quickload '(drakma yason uiop cl-ppcre trivia alexandria spinneret local-time)) 6 6 7 - (defconstant +user_did+ "did:plc:gijpvbkdbr56kazbdjhfvb3d") 8 - (defconstant +viewer+ "https://amybunny.leaflet.pub/%s" 7 + (defconstant +user-did+ "did:plc:gijpvbkdbr56kazbdjhfvb3d" 8 + "DID of the user to fetch entries from") 9 + (defconstant +viewer+ "https://amybunny.leaflet.pub/~A" 9 10 "URL to standard.site compliant viewer. Default is leaflet. 10 - %s is passed to `format' with the CID of the record.") 11 - (defconstant +max-entries+ 5) 11 + ~A is passed to `format' with the CID of the record.") 12 + (defconstant +max-entries+ 5 13 + "Maximum amount of entries fetched.") 12 14 13 15 ;; utilities 14 16 (defmacro run-command (command) ··· 30 32 31 33 (defun git-commit (message) 32 34 (run-command `("git" "commit" "-m" ,(concatenate 'string "[fallback-gen] " message)))) 35 + 36 + (defun git-push () 37 + (run-command '("git push"))) 33 38 ;; HTTP 34 39 (defun build-query-params-from-plist (parameters) 35 40 "Build a string of URL-encoded query parameters from a plist." ··· 106 111 (let ((title (get-in entry (:value :title))) 107 112 (description (or (get-in entry (:value :description)) "")) 108 113 (date (get-in entry (:value :publishedat))) 109 - (link "todo") 114 + (link (format nil +viewer+ (car (last (uiop:split-string (getf entry :uri) :separator '(#\/)))))) 110 115 (spinneret:*html-style* :tree)) 111 116 (spinneret:with-html-string 112 117 (:div.entry ··· 117 122 (published-at-element date)))))) 118 123 119 124 (defun generate-html (entries) 120 - (format nil "~{~A~^\n~}" (mapcar #'entry-element entries))) 125 + (format nil "~%~{~A~^~%~}~%" (mapcar #'entry-element entries))) 126 + 127 + (defun read-file-to-string (path) 128 + (with-open-file (stream path :direction :input :if-does-not-exist :error) 129 + (let ((buf (make-string (file-length stream)))) 130 + (read-sequence buf stream) 131 + buf))) 132 + 133 + (defun write-to-noscript-block (page entries) 134 + (let* ((fragment (generate-html entries)) 135 + (file-content (read-file-to-string page)) 136 + (start-pos (or (search "<noscript>" file-content) 137 + (error "Could not find opening tag in ~A" page))) 138 + (end-pos (or (search "</noscript>" file-content) 139 + (error "Could not find closing tag in ~A" page))) 140 + (insert-start (+ start-pos (length "<noscript>"))) 141 + (before (subseq file-content 0 insert-start)) 142 + (after (subseq file-content end-pos))) 143 + (with-open-file (file page :direction :output :if-exists :supersede) 144 + (write-string (concatenate 'string before fragment after) file)))) 145 + 146 + (defun publish () 147 + (let ((records (getf (fetch-entries +user-did+ 148 + +max-entries+) :records))) 149 + (write-to-noscript-block #p"./index.html" 150 + records) 151 + (git-add "index.html") 152 + (git-commit "chore(ci): generate noscript fallback") 153 + (git-push)))