More comments and docs tweaks.

This commit is contained in:
Brit Butler 2014-04-15 19:25:19 -04:00
parent e44dcbf05d
commit f2bd0ff0ef
3 changed files with 35 additions and 22 deletions

View file

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

View file

@ -1,5 +1,7 @@
(in-package :coleslaw)
;; Tagging
(defclass tag ()
((name :initform nil :initarg :name :accessor tag-name)
(slug :initform nil :Initarg :slug :accessor tag-slug)))
@ -13,21 +15,27 @@
"Test if the slugs for tag A and B are equal."
(string= (tag-slug a) (tag-slug b)))
;; Slugs
(defun slug-char-p (char)
"Determine if CHAR is a valid slug (i.e. URL) character."
(or (char<= #\0 char #\9)
(char<= #\a char #\z)
(char<= #\A char #\Z)
(member char '(#\_ #\-))))
(defun slugify (string)
"Return a version of STRING suitable for use as a URL."
(remove-if-not #'slug-char-p (substitute #\- #\Space string)))
;; Content Types
(defclass content ()
((tags :initform nil :initarg :tags :accessor content-tags)
(slug :initform nil :initarg :slug :accessor content-slug)
(date :initform nil :initarg :date :accessor content-date)
(text :initform nil :initarg :text :accessor content-text)))
(defun tag-p (tag obj)
"Test if OBJ is tagged with TAG."
(let ((tag (if (typep tag 'tag) tag (make-tag tag))))
(member tag (content-tags obj) :test #'tag-slug=)))
(defun month-p (month obj)
"Test if OBJ was written in MONTH."
(search month (content-date obj)))
(defun read-content (file)
"Returns a plist of metadata from FILE with :text holding the content as a string."
(flet ((slurp-remainder (stream)
@ -52,17 +60,15 @@
(setf (getf meta :tags) (read-tags (getf meta :tags)))
(append meta (list :text content))))))
(defun tag-p (tag obj)
"Test if OBJ is tagged with TAG."
(let ((tag (if (typep tag 'tag) tag (make-tag tag))))
(member tag (content-tags obj) :test #'tag-slug=)))
(defun month-p (month obj)
"Test if OBJ was written in MONTH."
(search month (content-date obj)))
(defun by-date (content)
"Sort CONTENT in reverse chronological order."
(sort content #'string> :key #'content-date))
(defun slug-char-p (char)
"Determine if CHAR is a valid slug (i.e. URL) character."
(or (char<= #\0 char #\9)
(char<= #\a char #\z)
(char<= #\A char #\Z)
(member char '(#\_ #\-))))
(defun slugify (string)
"Return a version of STRING suitable for use as a URL."
(remove-if-not #'slug-char-p (substitute #\- #\Space string)))

View file

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