Update storage of injections to support predicates.
This commit is contained in:
parent
395897e758
commit
04ada1eaea
3 changed files with 23 additions and 11 deletions
|
@ -15,8 +15,7 @@ Additional args to render CONTENT can be passed via RENDER-ARGS."
|
||||||
:content content
|
:content content
|
||||||
:raw (apply 'render content render-args)
|
:raw (apply 'render content render-args)
|
||||||
:pubdate (make-pubdate)
|
:pubdate (make-pubdate)
|
||||||
:body-inject (gethash :body *injections*)
|
:injections (find-injections content)))))
|
||||||
:head-inject (gethash :head *injections*)))))
|
|
||||||
(ensure-directories-exist filepath)
|
(ensure-directories-exist filepath)
|
||||||
(with-open-file (out filepath
|
(with-open-file (out filepath
|
||||||
:direction :output
|
:direction :output
|
||||||
|
|
|
@ -1,12 +1,18 @@
|
||||||
(in-package :coleslaw)
|
(in-package :coleslaw)
|
||||||
|
|
||||||
(defparameter *injections* (make-hash-table :test #'equal)
|
(defparameter *injections* ()
|
||||||
"A hash table for storing JS to inject in the theme templates.")
|
"A list that stores pairs of (string . predicate) to inject in the page.")
|
||||||
|
|
||||||
(defgeneric add-injection (str location)
|
(defun add-injection (injection location)
|
||||||
(:documentation "Add STR to the list of elements injected in LOCATION.")
|
(push injection (getf *injections* location)))
|
||||||
(:method ((str string) location)
|
|
||||||
(pushnew str (gethash location *injections*) :test #'string=)))
|
(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*)))
|
(defun theme-package (&key (name (theme *config*)))
|
||||||
"Find the package matching the theme NAME."
|
"Find the package matching the theme NAME."
|
||||||
|
@ -30,4 +36,3 @@
|
||||||
;; {template base}
|
;; {template base}
|
||||||
;; {template post}
|
;; {template post}
|
||||||
;; {template index}
|
;; {template index}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,11 @@
|
||||||
<link href="http://fonts.googleapis.com/css?family=Inconsolata" rel="stylesheet" type="text/css" />
|
<link href="http://fonts.googleapis.com/css?family=Inconsolata" rel="stylesheet" type="text/css" />
|
||||||
<link href= "{$config.domain}/css/style.css" rel="stylesheet" type="text/css" />
|
<link href= "{$config.domain}/css/style.css" rel="stylesheet" type="text/css" />
|
||||||
<link rel="alternate" href="{$config.domain}/rss.xml" type="application/rss+xml" />
|
<link rel="alternate" href="{$config.domain}/rss.xml" type="application/rss+xml" />
|
||||||
{if $headInject} {$headInject |noAutoescape} {/if}
|
{if $injections.head}
|
||||||
|
{foreach $injection in $injections.head}
|
||||||
|
{$injection |noAutoescape}
|
||||||
|
{/foreach}
|
||||||
|
{/if}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="navigation">
|
<div class="navigation">
|
||||||
|
@ -23,7 +27,11 @@
|
||||||
<div id="content">
|
<div id="content">
|
||||||
{$raw |noAutoescape}
|
{$raw |noAutoescape}
|
||||||
</div>
|
</div>
|
||||||
{if $bodyInject} {$bodyInject |noAutoescape} {/if}
|
{if $injections.body}
|
||||||
|
{foreach $injection in $injections.body}
|
||||||
|
{$injection |noAutoescape}
|
||||||
|
{/foreach}
|
||||||
|
{/if}
|
||||||
<div class="fineprint">
|
<div class="fineprint">
|
||||||
<hr>
|
<hr>
|
||||||
Unless otherwise credited all material
|
Unless otherwise credited all material
|
||||||
|
|
Loading…
Add table
Reference in a new issue