From 4f6006cfcfbc1113a5c28a516a2b4d7bc87f065f Mon Sep 17 00:00:00 2001 From: Brit Butler Date: Mon, 28 Apr 2014 13:15:36 -0400 Subject: [PATCH 1/7] First pass at static-pages as a plugin. --- plugins/static-pages.lisp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 plugins/static-pages.lisp diff --git a/plugins/static-pages.lisp b/plugins/static-pages.lisp new file mode 100644 index 0000000..091b2be --- /dev/null +++ b/plugins/static-pages.lisp @@ -0,0 +1,24 @@ +(defpackage :coleslaw-static-pages + (:use :cl) + (:export #:enable) + (:import-from :coleslaw #:content + #:page-url + #:find-all + #:render + #:publish)) + +(in-package :coleslaw-static-pages) + +(defclass page (content) + ((:url :initarg :url :reader page-url))) + +(defmethod render ((object page)) + ;; For now, we'll re-use the normal post theme. + (funcall (theme-fn 'post) (list :config *config* + :post object))) + +(defmethod publish ((doc-type (eql (find-class 'page)))) + (dolist (page (find-all 'page)) + (write-file (page-path page) (render-page page nil)))) + +(defun enable ()) From cba6776afd999a8f5291ea6c4fbb93e1a99ae833 Mon Sep 17 00:00:00 2001 From: Brit Butler Date: Mon, 28 Apr 2014 13:42:44 -0400 Subject: [PATCH 2/7] Cleanup imports and use write-document. --- plugins/static-pages.lisp | 12 +++++++----- src/packages.lisp | 1 + 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/plugins/static-pages.lisp b/plugins/static-pages.lisp index 091b2be..3cf142c 100644 --- a/plugins/static-pages.lisp +++ b/plugins/static-pages.lisp @@ -1,24 +1,26 @@ (defpackage :coleslaw-static-pages (:use :cl) (:export #:enable) - (:import-from :coleslaw #:content + (:import-from :coleslaw #:*config* + #:content #:page-url #:find-all #:render - #:publish)) + #:publish + #:write-document)) (in-package :coleslaw-static-pages) (defclass page (content) - ((:url :initarg :url :reader page-url))) + ((url :initarg :url :reader page-url))) -(defmethod render ((object page)) +(defmethod render ((object page) &key next prev) ;; For now, we'll re-use the normal post theme. (funcall (theme-fn 'post) (list :config *config* :post object))) (defmethod publish ((doc-type (eql (find-class 'page)))) (dolist (page (find-all 'page)) - (write-file (page-path page) (render-page page nil)))) + (write-document page))) (defun enable ()) diff --git a/src/packages.lisp b/src/packages.lisp index 6c7b774..7b59711 100644 --- a/src/packages.lisp +++ b/src/packages.lisp @@ -15,6 +15,7 @@ #:index #:render-text #:add-injection + #:theme-fn ;; The Document Protocol #:add-document #:find-all From a8a2a391ca224b74acf5fc5663360a2c96623776 Mon Sep 17 00:00:00 2001 From: Brit Butler Date: Mon, 28 Apr 2014 17:52:16 -0400 Subject: [PATCH 3/7] Add minor comment. --- src/content.lisp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/content.lisp b/src/content.lisp index dde3541..c818e0c 100644 --- a/src/content.lisp +++ b/src/content.lisp @@ -60,6 +60,8 @@ (setf (getf meta :tags) (read-tags (getf meta :tags))) (append meta (list :text content)))))) +;; Helper Functions + (defun tag-p (tag obj) "Test if OBJ is tagged with TAG." (let ((tag (if (typep tag 'tag) tag (make-tag tag)))) From 0e70d8661e0303c2927f3cf116e75174dbe3ea01 Mon Sep 17 00:00:00 2001 From: Brit Butler Date: Tue, 29 Apr 2014 00:03:59 -0400 Subject: [PATCH 4/7] 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. --- src/content.lisp | 10 ++++++---- themes/hyde/post.tmpl | 14 +++++++++----- themes/readable/post.tmpl | 18 ++++++++++++------ 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/content.lisp b/src/content.lisp index c818e0c..a80fc1f 100644 --- a/src/content.lisp +++ b/src/content.lisp @@ -36,6 +36,11 @@ (date :initform nil :initarg :date :accessor content-date) (text :initform nil :initarg :text :accessor content-text))) +(defmethod initialize-instance :after ((object content) &key) + (with-accessors ((tags content-tags)) object + (when (stringp tags) + (setf tags (mapcar #'make-tag (cl-ppcre:split "," tags)))))) + (defun read-content (file) "Returns a plist of metadata from FILE with :text holding the content as a string." (flet ((slurp-remainder (stream) @@ -46,9 +51,7 @@ (parse-field (str) (nth-value 1 (cl-ppcre:scan-to-strings "[a-zA-Z]+: (.*)" str))) (field-name (line) - (make-keyword (string-upcase (subseq line 0 (position #\: line))))) - (read-tags (str) - (mapcar #'make-tag (cl-ppcre:split "," str)))) + (make-keyword (string-upcase (subseq line 0 (position #\: line)))))) (with-open-file (in file :external-format '(:utf-8)) (unless (string= (read-line in) (separator *config*)) (error "The provided file lacks the expected header.")) @@ -57,7 +60,6 @@ appending (list (field-name line) (aref (parse-field line) 0)))) (content (slurp-remainder in))) - (setf (getf meta :tags) (read-tags (getf meta :tags))) (append meta (list :text content)))))) ;; Helper Functions diff --git a/themes/hyde/post.tmpl b/themes/hyde/post.tmpl index 6406035..3c514cd 100644 --- a/themes/hyde/post.tmpl +++ b/themes/hyde/post.tmpl @@ -4,13 +4,17 @@ {\n}
{\n} diff --git a/themes/readable/post.tmpl b/themes/readable/post.tmpl index a5be92f..b655ce7 100644 --- a/themes/readable/post.tmpl +++ b/themes/readable/post.tmpl @@ -3,13 +3,19 @@ {template post}
{\n}

{$post.title}

{\n} -

Tagged as - {foreach $tag in $post.tags} - {$tag.name}{nil} - {if not isLast($tag)},{sp}{/if} - {/foreach} +

+ {if $post.tags} + Tagged as {foreach $tag in $post.tags} + {$tag.name}{nil} + {if not isLast($tag)},{sp}{/if} + {/foreach} + {/if} +

+

+ {if $post.date} + Written on {$post.date} + {/if}

-

Written on {$post.date}

{$post.text |noAutoescape} From 3bf0bcf337c4fccae8d178a10b340a8aa0df0b05 Mon Sep 17 00:00:00 2001 From: Brit Butler Date: Tue, 29 Apr 2014 00:13:40 -0400 Subject: [PATCH 5/7] Tweak hyde/post indentation a bit. --- themes/hyde/post.tmpl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/themes/hyde/post.tmpl b/themes/hyde/post.tmpl index 3c514cd..cebe759 100644 --- a/themes/hyde/post.tmpl +++ b/themes/hyde/post.tmpl @@ -6,9 +6,9 @@
{\n} {if $post.tags} Tagged as {foreach $tag in $post.tags} - {$tag.name}{nil} - {if not isLast($tag)},{sp}{/if} - {/foreach} + {$tag.name}{nil} + {if not isLast($tag)},{sp}{/if} + {/foreach} {/if}
{\n}
{\n} From f1abdd5410c2a9731da357e1fb83d6fa0bc95dc3 Mon Sep 17 00:00:00 2001 From: Brit Butler Date: Tue, 29 Apr 2014 00:20:46 -0400 Subject: [PATCH 6/7] Add a title and treat static-pages as markdown. --- plugins/static-pages.lisp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/plugins/static-pages.lisp b/plugins/static-pages.lisp index 3cf142c..66d276a 100644 --- a/plugins/static-pages.lisp +++ b/plugins/static-pages.lisp @@ -12,10 +12,16 @@ (in-package :coleslaw-static-pages) (defclass page (content) - ((url :initarg :url :reader page-url))) + ((title :initarg :title :reader page-title) + (url :initarg :url :reader page-url))) + +(defmethod initialize-instance :after ((object page) &key) + ;; Expect all static-pages to be written in Markdown for now. + (with-accessors ((text content-text)) object + (setf text (render-text text :md)))) (defmethod render ((object page) &key next prev) - ;; For now, we'll re-use the normal post theme. + ;; For the time being, we'll re-use the normal post theme. (funcall (theme-fn 'post) (list :config *config* :post object))) From 0446b5f919bbdf49759ba268c0cb9be79c169c08 Mon Sep 17 00:00:00 2001 From: Brit Butler Date: Tue, 29 Apr 2014 14:03:44 -0400 Subject: [PATCH 7/7] Add some NEWS entries and remove the TODO item from hacking.md. --- NEWS.md | 8 ++++++++ docs/hacking.md | 19 ------------------- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/NEWS.md b/NEWS.md index 3330d7f..fd65e1f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -7,6 +7,14 @@ the old behavior. * Coleslaw no longer expects a particular repo layout. Use whatever directory hierarchy you like. +* New Content Type Plugin: Static Pages, accepting a title, url, and + optionally tags and a date. All files with a `.page` extension are + compiled as static pages and reuse the POST template. + To enable Static Pages, add `(static-pages)` to the `:plugins` + section of your config. +* Coleslaw now allows content without a date or tags. Note that POSTs + without a date will still show up in the reverse chronological + indexes at the very end. ## Changes for 0.9.3 (2013-04-16): diff --git a/docs/hacking.md b/docs/hacking.md index 327bbd7..f8adae3 100644 --- a/docs/hacking.md +++ b/docs/hacking.md @@ -168,25 +168,6 @@ freshly built site. ## Areas for Improvement -### Allow Tagless or Dateless Content - -Several users have expected to be able to not supply tags or a date -for their content. This is a reasonable expectation and requires -changes to at least the post templates and the `read-content` -function. There may be other areas where it was assumed tags/dates -will always be present. - -### New Content Type: Pages! - -Many users have requested a content type PAGE, for static pages. It -should be a pretty straightforward subclass of CONTENT with the -necessary methods: `render`, `page-url` and `publish`. It could have a -`url` slot with `page-url` as a reader to allow arbitrary layout on -the site. For now, we can be sloppy and reuse the post template and -limit static-pages to being written in markdown. If we want to support -other formats, consider moving the format slot from POST to CONTENT. -This has been implemented on the branch `static-pages`. - ### New Content Type: Shouts! I've also toyed with the idea of a content type called a SHOUT, which