Compare commits

...
Sign in to create a new pull request.

1 commit

Author SHA1 Message Date
Javier Olaechea
e85bbb0e7e Add register-content-class 2015-09-30 00:10:43 -05:00
3 changed files with 29 additions and 7 deletions

View file

@ -60,6 +60,9 @@
(when (stringp tags)
(setf tags (mapcar #'make-tag (cl-ppcre:split "," tags))))))
(register-content-class "md" (find-class 'content))
(register-content-class "post" (find-class 'content))
(defun parse-initarg (line)
"Given a metadata header, LINE, parse an initarg name/value pair from it."
(let ((name (string-upcase (subseq line 0 (position #\: line))))

View file

@ -7,18 +7,36 @@
(defvar *site* (make-hash-table :test #'equal)
"An in-memory database to hold all site documents, keyed on relative URLs.")
(defvar *file-extension-content-class* (make-hash-table :test #'equalp)
"Maps a file extension to a content-class/document-type.")
(defun register-content-class (file-extension document-type)
"Informs that files with the FILE-EXTENSION should belong to the DOCUMENT-TYPE."
(setf (gethash file-extension *file-extension-content-class*) document-type))
;; Class Methods
(defgeneric publish (doc-type)
(:documentation "Write pages to disk for all documents of the given DOC-TYPE."))
(defgeneric discover (doc-type)
(:documentation "Load all documents of the given DOC-TYPE into memory.")
(:method (doc-type)
(let ((file-type (format nil "~(~A~)" (class-name doc-type))))
(:documentation "Load all documents of the given DOC-TYPE into memory."))
(defun doc-type-file-types (doc-type)
"Return a list containing all the valid file-types for doc-type"
(let (results)
(loop
:for file-type :being :the :hash-keys :of *file-extension-content-class*
:using (hash-value document-type)
:when (eq doc-type document-type)
:do (push file-type results))
results))
(defmethod discover (doc-type)
(dolist (file-type (doc-type-file-types doc-type))
(do-files (file (repo-dir *config*) file-type)
(let ((obj (construct (class-name doc-type) (read-content file))))
(add-document obj))))))
(add-document obj)))))
(defmethod discover :before (doc-type)
(purge-all (class-name doc-type)))

View file

@ -38,4 +38,5 @@
#:add-document
#:delete-document
#:write-document
#:content-text))
#:content-text
#:register-content-class))