diff --git a/src/coleslaw.lisp b/src/coleslaw.lisp index ce8b1f6..df6abdb 100644 --- a/src/coleslaw.lisp +++ b/src/coleslaw.lisp @@ -15,8 +15,7 @@ Additional args to render CONTENT can be passed via RENDER-ARGS." :content content :raw (apply 'render content render-args) :pubdate (make-pubdate) - :body-inject (gethash :body *injections*) - :head-inject (gethash :head *injections*))))) + :injections (find-injections content))))) (ensure-directories-exist filepath) (with-open-file (out filepath :direction :output diff --git a/src/themes.lisp b/src/themes.lisp index 8208b19..b791c48 100644 --- a/src/themes.lisp +++ b/src/themes.lisp @@ -1,12 +1,18 @@ (in-package :coleslaw) -(defparameter *injections* (make-hash-table :test #'equal) - "A hash table for storing JS to inject in the theme templates.") +(defparameter *injections* () + "A list that stores pairs of (string . predicate) to inject in the page.") -(defgeneric add-injection (str location) - (:documentation "Add STR to the list of elements injected in LOCATION.") - (:method ((str string) location) - (pushnew str (gethash location *injections*) :test #'string=))) +(defun add-injection (injection location) + (push injection (getf *injections* location))) + +(defun find-injections (content) + (flet ((injections-for (location) + (loop for (injection . predicate) in (getf *injections* location) + when (funcall predicate content) + collect injection))) + (list :head (injections-for :head) + :body (injections-for :body)))) (defun theme-package (&key (name (theme *config*))) "Find the package matching the theme NAME." @@ -30,4 +36,3 @@ ;; {template base} ;; {template post} ;; {template index} - diff --git a/themes/hyde/base.tmpl b/themes/hyde/base.tmpl index 9864cf4..a7aaa74 100644 --- a/themes/hyde/base.tmpl +++ b/themes/hyde/base.tmpl @@ -10,7 +10,11 @@ - {if $headInject} {$headInject |noAutoescape} {/if} + {if $injections.head} + {foreach $injection in $injections.head} + {$injection |noAutoescape} + {/foreach} + {/if}