Compare commits
1 commit
master
...
extend-con
Author | SHA1 | Date | |
---|---|---|---|
![]() |
e85bbb0e7e |
3 changed files with 29 additions and 7 deletions
|
@ -60,6 +60,9 @@
|
||||||
(when (stringp tags)
|
(when (stringp tags)
|
||||||
(setf tags (mapcar #'make-tag (cl-ppcre:split "," 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)
|
(defun parse-initarg (line)
|
||||||
"Given a metadata header, LINE, parse an initarg name/value pair from it."
|
"Given a metadata header, LINE, parse an initarg name/value pair from it."
|
||||||
(let ((name (string-upcase (subseq line 0 (position #\: line))))
|
(let ((name (string-upcase (subseq line 0 (position #\: line))))
|
||||||
|
|
|
@ -7,18 +7,36 @@
|
||||||
(defvar *site* (make-hash-table :test #'equal)
|
(defvar *site* (make-hash-table :test #'equal)
|
||||||
"An in-memory database to hold all site documents, keyed on relative URLs.")
|
"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
|
;; Class Methods
|
||||||
|
|
||||||
(defgeneric publish (doc-type)
|
(defgeneric publish (doc-type)
|
||||||
(:documentation "Write pages to disk for all documents of the given DOC-TYPE."))
|
(:documentation "Write pages to disk for all documents of the given DOC-TYPE."))
|
||||||
|
|
||||||
(defgeneric discover (doc-type)
|
(defgeneric discover (doc-type)
|
||||||
(:documentation "Load all documents of the given DOC-TYPE into memory.")
|
(:documentation "Load all documents of the given DOC-TYPE into memory."))
|
||||||
(:method (doc-type)
|
|
||||||
(let ((file-type (format nil "~(~A~)" (class-name doc-type))))
|
(defun doc-type-file-types (doc-type)
|
||||||
(do-files (file (repo-dir *config*) file-type)
|
"Return a list containing all the valid file-types for doc-type"
|
||||||
(let ((obj (construct (class-name doc-type) (read-content file))))
|
(let (results)
|
||||||
(add-document obj))))))
|
(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)))))
|
||||||
|
|
||||||
(defmethod discover :before (doc-type)
|
(defmethod discover :before (doc-type)
|
||||||
(purge-all (class-name doc-type)))
|
(purge-all (class-name doc-type)))
|
||||||
|
|
|
@ -38,4 +38,5 @@
|
||||||
#:add-document
|
#:add-document
|
||||||
#:delete-document
|
#:delete-document
|
||||||
#:write-document
|
#:write-document
|
||||||
#:content-text))
|
#:content-text
|
||||||
|
#:register-content-class))
|
||||||
|
|
Loading…
Add table
Reference in a new issue