Selaa lähdekoodia

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.
Brit Butler 11 vuotta sitten
vanhempi
commit
0e70d8661e
3 muutettua tiedostoa jossa 27 lisäystä ja 15 poistoa
  1. 6 4
      src/content.lisp
  2. 9 5
      themes/hyde/post.tmpl
  3. 12 6
      themes/readable/post.tmpl

+ 6 - 4
src/content.lisp

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

+ 9 - 5
themes/hyde/post.tmpl

@@ -4,13 +4,17 @@
4 4
 <div class="article-meta">{\n}
5 5
   <h1 class="title">{$post.title}</h1>{\n}
6 6
   <div class="tags">{\n}
7
-    Tagged as {foreach $tag in $post.tags}
8
-                <a href="../tag/{$tag.slug}.{$config.pageExt}">{$tag.name}</a>{nil}
9
-                    {if not isLast($tag)},{sp}{/if}
10
-              {/foreach}
7
+    {if $post.tags}
8
+      Tagged as {foreach $tag in $post.tags}
9
+                  <a href="../tag/{$tag.slug}.{$config.pageExt}">{$tag.name}</a>{nil}
10
+                      {if not isLast($tag)},{sp}{/if}
11
+                {/foreach}
12
+    {/if}
11 13
   </div>{\n}
12 14
   <div class="date">{\n}
13
-    Written on {$post.date}
15
+    {if $post.date}
16
+      Written on {$post.date}
17
+    {/if}
14 18
   </div>{\n}
15 19
 </div>{\n}
16 20
 <div class="article-content">{\n}

+ 12 - 6
themes/readable/post.tmpl

@@ -3,13 +3,19 @@
3 3
 {template post}
4 4
 <div class="row-fluid">{\n}
5 5
   <h1 class="page-header">{$post.title}</h1>{\n}
6
-  <p>Tagged as 
7
-    {foreach $tag in $post.tags}
8
-      <a href="../tag/{$tag.slug}{$config.pageExt}">{$tag.name}</a>{nil}
9
-      {if not isLast($tag)},{sp}{/if}
10
-    {/foreach}
6
+  <p>
7
+    {if $post.tags}
8
+      Tagged as {foreach $tag in $post.tags}
9
+        <a href="../tag/{$tag.slug}{$config.pageExt}">{$tag.name}</a>{nil}
10
+          {if not isLast($tag)},{sp}{/if}
11
+      {/foreach}
12
+    {/if}
13
+  </p>
14
+  <p class="date-posted">
15
+    {if $post.date}
16
+      Written on {$post.date}
17
+    {/if}
11 18
   </p>
12
-  <p class="date-posted">Written on {$post.date}</p>
13 19
 
14 20
   {$post.text |noAutoescape}
15 21