miniblog

Miniblog: A command-line static blog system in Common Lisp
Log | Files | Refs | README | LICENSE

commit 3330ab0982aba59f0773be9561e109537cb427e0
parent 9252c2a87651e271b84a3c916002bc0aab860d28
Author: Decay <decaydjk@tilde.town>
Date:   Mon,  3 Feb 2020 23:26:46 +0000

Add eco template and some supporting mechanisms

Diffstat:
Mminiblog.asd | 4++++
Asrc/format.lisp | 26++++++++++++++++++++++++++
Msrc/packages.lisp | 6++++++
Asrc/template.eco | 29+++++++++++++++++++++++++++++
4 files changed, 65 insertions(+), 0 deletions(-)

diff --git a/miniblog.asd b/miniblog.asd @@ -5,13 +5,17 @@ :depends-on ("uiop" "cl-fad" "cl-markdown" + "eco" "dbd-sqlite3" "sxql" "mito" "local-time") + :defsystem-depends-on (:eco) :pathname "src/" :entry-point "miniblog:main" :components ((:file "packages") + (:file "format") (:file "edit") (:file "db") + (:eco-template "template") (:file "miniblog"))) diff --git a/src/format.lisp b/src/format.lisp @@ -0,0 +1,26 @@ +(in-package :miniblog.format) + +(defparameter +short-date-format+ + '((:year 4) #\- (:month 2) #\- (:day 2)) + "Date in YYYY-MM-DD format") + +(defparameter +long-date-format+ + '(:long-weekday ", " :long-month #\ :ordinal-day #\ (:year 4) + " at " :hour12 #\: (:min 2) #\ :ampm #\ :timezone) + "Long format datetime, like: + Monday, February 3rd 2020 at 2:46 PM PST") + +(defun make-content-formatter () + "Return the default content formatter (parses Markdown)" + (lambda (content) + (nth 1 (multiple-value-list (markdown content :stream nil))))) + +(defun make-short-date-formatter () + "Return the default short-date formatter (see +short-date-format+)" + (lambda (datetime) + (format-timestring nil datetime :format +short-date-format+))) + +(defun make-long-date-formatter () + "Return the default long-datetime formatter (see +long-date-format+)" + (lambda (datetime) + (format-timestring nil datetime :format +long-date-format+))) diff --git a/src/packages.lisp b/src/packages.lisp @@ -1,5 +1,11 @@ (in-package :cl-user) +(defpackage :miniblog.format + (:use :cl :cl-markdown :local-time) + (:export #:make-content-formatter + #:make-short-date-formatter + #:make-long-date-formatter)) + (defpackage :miniblog.edit (:use :cl :uiop/os :uiop/run-program :cl-fad) (:export #:edit-text)) diff --git a/src/template.eco b/src/template.eco @@ -0,0 +1,29 @@ +<% deftemplate index (posts content-formatter short-date-formatter long-date-formatter &key title year month start-entry max-entries) (:escape-html nil) %> + <!DOCTYPE html> + <html> + <head> + <title><%= (or title "Miniblog") %></title> + </head> + <body> + <% if posts %> + <% let ((short-date)) %> + <% loop for (id created-at updated-at title content username last-updated-by) in posts do %> + <% let ((curr-short-date (funcall short-date-formatter created-at))) %> + <% if (string/= short-date curr-short-date) %> + <% setf short-date curr-short-date %><% end %> + <h1><%= short-date %></h1> + <% else %> + <% end %> + <% end %> + <h2><%= title %></h2> + <article> + <%= (funcall content-formatter content) %> + </article> + <% end %> + <% end %> + <% else %> + No posts found. + <% end %> + </body> + </html> +<% end %>