Explorar el Código

More comments and docs tweaks.

Brit Butler hace 11 años
padre
commit
f2bd0ff0ef
Se han modificado 3 ficheros con 35 adiciones y 22 borrados
  1. 8 1
      docs/hacking.md
  2. 26 20
      src/content.lisp
  3. 1 1
      src/documents.lisp

+ 8 - 1
docs/hacking.md

@@ -39,7 +39,7 @@ generator.  Content Types were added in 0.8 as a step towards making
39 39
 limitations. Chiefly, the association between Content Types, their
40 40
 template, and their inclusion in an INDEX is presently ad-hoc.
41 41
 
42
-// TODO: Write something about class-names as file-extension/eql-specializers!
42
+// TODO: Write something about the new Document Protocol!
43 43
 ### Current Content Types & Indexes
44 44
 
45 45
 There are 5 INDEX subclasses at present: TAG-INDEX, MONTH-INDEX,
@@ -106,7 +106,14 @@ freshly built site.
106 106
 
107 107
 ## Areas for Improvement
108 108
 
109
+### render-foo* functions could be abstracted out
110
+// TODO
111
+
112
+### user-defined routing
113
+// TODO
114
+
109 115
 ### Better Content Types
116
+// TODO: Update to discuss Document Protocol.
110 117
 
111 118
 Creating a new content type should be both straightforward and doable
112 119
 as a plugin. All that is really required is a subclass of CONTENT with

+ 26 - 20
src/content.lisp

@@ -1,5 +1,7 @@
1 1
 (in-package :coleslaw)
2 2
 
3
+;; Tagging
4
+
3 5
 (defclass tag ()
4 6
   ((name :initform nil :initarg :name :accessor tag-name)
5 7
    (slug :initform nil :Initarg :slug :accessor tag-slug)))
@@ -13,21 +15,27 @@
13 15
   "Test if the slugs for tag A and B are equal."
14 16
   (string= (tag-slug a) (tag-slug b)))
15 17
 
18
+;; Slugs
19
+
20
+(defun slug-char-p (char)
21
+  "Determine if CHAR is a valid slug (i.e. URL) character."
22
+  (or (char<= #\0 char #\9)
23
+      (char<= #\a char #\z)
24
+      (char<= #\A char #\Z)
25
+      (member char '(#\_ #\-))))
26
+
27
+(defun slugify (string)
28
+  "Return a version of STRING suitable for use as a URL."
29
+  (remove-if-not #'slug-char-p (substitute #\- #\Space string)))
30
+
31
+;; Content Types
32
+
16 33
 (defclass content ()
17 34
   ((tags :initform nil :initarg :tags :accessor content-tags)
18 35
    (slug :initform nil :initarg :slug :accessor content-slug)
19 36
    (date :initform nil :initarg :date :accessor content-date)
20 37
    (text :initform nil :initarg :text :accessor content-text)))
21 38
 
22
-(defun tag-p (tag obj)
23
-  "Test if OBJ is tagged with TAG."
24
-  (let ((tag (if (typep tag 'tag) tag (make-tag tag))))
25
-    (member tag (content-tags obj) :test #'tag-slug=)))
26
-
27
-(defun month-p (month obj)
28
-  "Test if OBJ was written in MONTH."
29
-  (search month (content-date obj)))
30
-
31 39
 (defun read-content (file)
32 40
   "Returns a plist of metadata from FILE with :text holding the content as a string."
33 41
   (flet ((slurp-remainder (stream)
@@ -52,17 +60,15 @@
52 60
         (setf (getf meta :tags) (read-tags (getf meta :tags)))
53 61
         (append meta (list :text content))))))
54 62
 
63
+(defun tag-p (tag obj)
64
+  "Test if OBJ is tagged with TAG."
65
+  (let ((tag (if (typep tag 'tag) tag (make-tag tag))))
66
+    (member tag (content-tags obj) :test #'tag-slug=)))
67
+
68
+(defun month-p (month obj)
69
+  "Test if OBJ was written in MONTH."
70
+  (search month (content-date obj)))
71
+
55 72
 (defun by-date (content)
56 73
   "Sort CONTENT in reverse chronological order."
57 74
   (sort content #'string> :key #'content-date))
58
-
59
-(defun slug-char-p (char)
60
-  "Determine if CHAR is a valid slug (i.e. URL) character."
61
-  (or (char<= #\0 char #\9)
62
-      (char<= #\a char #\z)
63
-      (char<= #\A char #\Z)
64
-      (member char '(#\_ #\-))))
65
-
66
-(defun slugify (string)
67
-  "Return a version of STRING suitable for use as a URL."
68
-  (remove-if-not #'slug-char-p (substitute #\- #\Space string)))

+ 1 - 1
src/documents.lisp

@@ -8,7 +8,7 @@
8 8
   "An in-memory database to hold all site documents, keyed on page-url.")
9 9
 
10 10
 (defun add-document (doc)
11
-  "Add DOC to the in-memory database. If a matching entry is present, error."
11
+  "Add DOC to the in-memory database. Error if a matching entry is present."
12 12
   (let ((url (page-url doc)))
13 13
     (if (gethash url *site*)
14 14
         (error "There is already an existing document with the url ~a" url)