Minimal changes to support tagless, dateless static-pages using post template.

Note that tagless or dateless posts might not behave as expected in
indexes. Filtering by tag still works but sorting by date doesn't
drop the nil values.
This commit is contained in:
Brit Butler 2014-04-29 00:03:59 -04:00
parent a8a2a391ca
commit 0e70d8661e
3 changed files with 27 additions and 15 deletions

View file

@ -36,6 +36,11 @@
(date :initform nil :initarg :date :accessor content-date)
(text :initform nil :initarg :text :accessor content-text)))
(defmethod initialize-instance :after ((object content) &key)
(with-accessors ((tags content-tags)) object
(when (stringp tags)
(setf tags (mapcar #'make-tag (cl-ppcre:split "," tags))))))
(defun read-content (file)
"Returns a plist of metadata from FILE with :text holding the content as a string."
(flet ((slurp-remainder (stream)
@ -46,9 +51,7 @@
(parse-field (str)
(nth-value 1 (cl-ppcre:scan-to-strings "[a-zA-Z]+: (.*)" str)))
(field-name (line)
(make-keyword (string-upcase (subseq line 0 (position #\: line)))))
(read-tags (str)
(mapcar #'make-tag (cl-ppcre:split "," str))))
(make-keyword (string-upcase (subseq line 0 (position #\: line))))))
(with-open-file (in file :external-format '(:utf-8))
(unless (string= (read-line in) (separator *config*))
(error "The provided file lacks the expected header."))
@ -57,7 +60,6 @@
appending (list (field-name line)
(aref (parse-field line) 0))))
(content (slurp-remainder in)))
(setf (getf meta :tags) (read-tags (getf meta :tags)))
(append meta (list :text content))))))
;; Helper Functions

View file

@ -4,13 +4,17 @@
<div class="article-meta">{\n}
<h1 class="title">{$post.title}</h1>{\n}
<div class="tags">{\n}
Tagged as {foreach $tag in $post.tags}
<a href="../tag/{$tag.slug}.{$config.pageExt}">{$tag.name}</a>{nil}
{if not isLast($tag)},{sp}{/if}
{/foreach}
{if $post.tags}
Tagged as {foreach $tag in $post.tags}
<a href="../tag/{$tag.slug}.{$config.pageExt}">{$tag.name}</a>{nil}
{if not isLast($tag)},{sp}{/if}
{/foreach}
{/if}
</div>{\n}
<div class="date">{\n}
Written on {$post.date}
{if $post.date}
Written on {$post.date}
{/if}
</div>{\n}
</div>{\n}
<div class="article-content">{\n}

View file

@ -3,13 +3,19 @@
{template post}
<div class="row-fluid">{\n}
<h1 class="page-header">{$post.title}</h1>{\n}
<p>Tagged as
{foreach $tag in $post.tags}
<a href="../tag/{$tag.slug}{$config.pageExt}">{$tag.name}</a>{nil}
{if not isLast($tag)},{sp}{/if}
{/foreach}
<p>
{if $post.tags}
Tagged as {foreach $tag in $post.tags}
<a href="../tag/{$tag.slug}{$config.pageExt}">{$tag.name}</a>{nil}
{if not isLast($tag)},{sp}{/if}
{/foreach}
{/if}
</p>
<p class="date-posted">
{if $post.date}
Written on {$post.date}
{/if}
</p>
<p class="date-posted">Written on {$post.date}</p>
{$post.text |noAutoescape}