From 0e70d8661e0303c2927f3cf116e75174dbe3ea01 Mon Sep 17 00:00:00 2001 From: Brit Butler Date: Tue, 29 Apr 2014 00:03:59 -0400 Subject: [PATCH] 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. --- src/content.lisp | 10 ++++++---- themes/hyde/post.tmpl | 14 +++++++++----- themes/readable/post.tmpl | 18 ++++++++++++------ 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/content.lisp b/src/content.lisp index c818e0c..a80fc1f 100644 --- a/src/content.lisp +++ b/src/content.lisp @@ -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 diff --git a/themes/hyde/post.tmpl b/themes/hyde/post.tmpl index 6406035..3c514cd 100644 --- a/themes/hyde/post.tmpl +++ b/themes/hyde/post.tmpl @@ -4,13 +4,17 @@
{\n}

{$post.title}

{\n}
{\n} - Tagged as {foreach $tag in $post.tags} - {$tag.name}{nil} - {if not isLast($tag)},{sp}{/if} - {/foreach} + {if $post.tags} + Tagged as {foreach $tag in $post.tags} + {$tag.name}{nil} + {if not isLast($tag)},{sp}{/if} + {/foreach} + {/if}
{\n}
{\n} - Written on {$post.date} + {if $post.date} + Written on {$post.date} + {/if}
{\n}
{\n}
{\n} diff --git a/themes/readable/post.tmpl b/themes/readable/post.tmpl index a5be92f..b655ce7 100644 --- a/themes/readable/post.tmpl +++ b/themes/readable/post.tmpl @@ -3,13 +3,19 @@ {template post}
{\n}

{$post.title}

{\n} -

Tagged as - {foreach $tag in $post.tags} - {$tag.name}{nil} - {if not isLast($tag)},{sp}{/if} - {/foreach} +

+ {if $post.tags} + Tagged as {foreach $tag in $post.tags} + {$tag.name}{nil} + {if not isLast($tag)},{sp}{/if} + {/foreach} + {/if} +

+

+ {if $post.date} + Written on {$post.date} + {/if}

-

Written on {$post.date}

{$post.text |noAutoescape}