diff --git a/src/content.lisp b/src/content.lisp index 0d610b20..00acb439 100644 --- a/src/content.lisp +++ b/src/content.lisp @@ -48,17 +48,32 @@ ;; Content Types (defclass content () - ((url :initarg :url :reader page-url) - (date :initarg :date :reader content-date) - (file :initarg :file :reader content-file) - (tags :initarg :tags :reader content-tags) - (text :initarg :text :reader content-text)) - (:default-initargs :tags nil :date nil)) + ((url :initarg :url :reader page-url) + (date :initarg :date :reader content-date) + (file :initarg :file :reader content-file) + (tags :initarg :tags :reader content-tags) + (text :initarg :text :reader content-text) + (bindings :initarg :bindings :reader content-bindings)) + (:default-initargs :tags nil :date nil :bindings nil :code nil)) + +(defun read-bindings-from-string (string) + "Read multiple pairs of values from STRING and return them as two LISTs +of variables and values ready to be passed into PROGV." + (with-input-from-string (stream string) + (loop + for variable = (read stream nil) + for value = (read stream nil) + while variable + collect variable into variables + collect value into values + finally (return (cons variables values))))) (defmethod initialize-instance :after ((object content) &key) - (with-slots (tags) object + (with-slots (tags bindings) object (when (stringp tags) - (setf tags (mapcar #'make-tag (cl-ppcre:split "," tags)))))) + (setf tags (mapcar #'make-tag (cl-ppcre:split "," tags)))) + (when bindings + (setf bindings (read-bindings-from-string bindings))))) (defun parse-initarg (line) "Given a metadata header, LINE, parse an initarg name/value pair from it." diff --git a/src/posts.lisp b/src/posts.lisp index d8fe29d5..d112d86b 100644 --- a/src/posts.lisp +++ b/src/posts.lisp @@ -7,11 +7,12 @@ (:default-initargs :author nil)) (defmethod initialize-instance :after ((object post) &key) - (with-slots (url title author format text) object - (setf url (compute-url object (slugify title)) - format (make-keyword (string-upcase format)) - text (render-text text format) - author (or author (author *config*))))) + (with-slots (url title author format text bindings) object + (progv (car bindings) (cdr bindings) + (setf url (compute-url object (slugify title)) + format (make-keyword (string-upcase format)) + text (render-text text format) + author (or author (author *config*)))))) (defmethod render ((object post) &key prev next) (funcall (theme-fn 'post) (list :config *config*