diff --git a/docs/hacking.md b/docs/hacking.md index e2c36a6..44069a8 100644 --- a/docs/hacking.md +++ b/docs/hacking.md @@ -224,11 +224,17 @@ PAGE, a content type for static page support, is available as a plugin. Right now, the templates break if you use a custom routing scheme in your config. This is flatly ridiculous. The templates should be updated to use a url field stored on each object which will store -the unified domain/path of the object. This can be done transparently -to users, though must be handled with care and may involve refactoring +the path of the object. This can be done transparently to users, +though must be handled with care and may involve refactoring in the document protocol. Test carefully. If we cheat by hardcoding the sitemap and/or feeds, that's probably okay for the moment. +Turns out this is even messier than I thought. Links are built from +scratch in the templates *all over the place*. Tags in posts, +taglinks and monthlinks in indexes, and prev/next links in numeric +indexes. I'm also doing two `find-all` calls in the base `render` +method for index. So I should profile and/or memoize that if needed. + ### Clean up Slugs vs Paths Currently, we track uniqueness in the site by using a hashtable diff --git a/src/content.lisp b/src/content.lisp index aa7cf72..90891eb 100644 --- a/src/content.lisp +++ b/src/content.lisp @@ -33,8 +33,9 @@ (defclass content () ((file :initarg :file :reader content-file) (date :initarg :date :reader content-date) + (path :initarg :path :accessor path-of) + (slug :initarg :slug :accessor slug-of) (tags :initarg :tags :accessor content-tags) - (slug :initarg :slug :accessor content-slug) (text :initarg :text :accessor content-text)) (:default-initargs :tags nil :date nil :slug nil)) diff --git a/src/documents.lisp b/src/documents.lisp index 3c398dd..82f0c66 100644 --- a/src/documents.lisp +++ b/src/documents.lisp @@ -29,14 +29,14 @@ (:documentation "The url to the DOCUMENT without the domain.") (:method (document) (let* ((class-name (class-name (class-of document))) - (route (assoc (make-keyword class-name) (routing *config*)))) + (route (get-route class-name))) (if route - (format nil (second route) (slot-value document 'slug)) + (format nil route (slug-of document)) (error "No routing method found for: ~A" class-name))))) (defmethod page-url :around ((document t)) (let* ((result (call-next-method)) - (type (or (pathname-type result) "html"))) + (type (or (pathname-type result) (page-ext *config*)))) (make-pathname :type type :defaults result))) (defgeneric render (document &key &allow-other-keys) @@ -64,6 +64,10 @@ use it as the template passing any RENDER-ARGS." (url (namestring (page-url document)))) (write-file (rel-path (staging-dir *config*) url) html))) +(defun get-route (doc-type) + "Return the route format string for DOC-TYPE." + (second (assoc (make-keyword doc-type) (routing *config*)))) + (defun find-all (doc-type) "Return a list of all instances of a given DOC-TYPE." (loop for val being the hash-values in *site* diff --git a/src/indexes.lisp b/src/indexes.lisp index eaf0807..cb07a21 100644 --- a/src/indexes.lisp +++ b/src/indexes.lisp @@ -6,13 +6,17 @@ "The list of tags which content has been tagged with.") (defclass index () - ((slug :initarg :slug :reader index-slug) + ((path :initarg :path :accessor path-of) + (slug :initarg :slug :reader slug-of) (title :initarg :title :reader title-of) (content :initarg :content :reader index-content))) +(defmethod initialize-instance :after ((object index) &key) + (setf (path-of object) (page-url object))) + (defmethod render ((object index) &key prev next) - (funcall (theme-fn 'index) (list :tags *all-tags* - :months *all-months* + (funcall (theme-fn 'index) (list :tags (find-all 'tag-index) + :months (find-all 'month-index) :config *config* :index object :prev prev @@ -24,7 +28,7 @@ (defmethod discover ((doc-type (eql (find-class 'tag-index)))) (let ((content (by-date (find-all 'post)))) - (dolist (tag (all-tags)) + (dolist (tag *all-tags*) (add-document (index-by-tag tag content))))) (defun index-by-tag (tag content) diff --git a/src/posts.lisp b/src/posts.lisp index ebfc2c2..ac30554 100644 --- a/src/posts.lisp +++ b/src/posts.lisp @@ -11,10 +11,11 @@ (author author-of) (format post-format) (text content-text)) object - (setf (content-slug object) (slugify title) - format (make-keyword (string-upcase format)) - text (render-text text format) - author (or author (author *config*))))) + (setf (slug-of object) (slugify title) + (path-of object) (page-url object) + format (make-keyword (string-upcase format)) + text (render-text text format) + author (or author (author *config*))))) (defmethod render ((object post) &key prev next) (funcall (theme-fn 'post) (list :config *config* diff --git a/themes/atom.tmpl b/themes/atom.tmpl index 761f684..6061503 100644 --- a/themes/atom.tmpl +++ b/themes/atom.tmpl @@ -14,7 +14,7 @@ {foreach $post in $content.content} - + {$post.title} {$post.date} {$post.date} diff --git a/themes/hyde/index.tmpl b/themes/hyde/index.tmpl index 9100fdf..954eeb8 100644 --- a/themes/hyde/index.tmpl +++ b/themes/hyde/index.tmpl @@ -4,20 +4,20 @@

{$index.title}

{foreach $obj in $index.content}
- {$obj.title} + {$obj.title}
posted on {$obj.date}
{$obj.text |noAutoescape}
{/foreach}
- {if $prev} Previous {/if} - {if $next} Next {/if} + {if $prev} Previous {/if} + {if $next} Next {/if}
{if $tags}

This blog covers {foreach $tag in $tags} - {$tag.name}{nil} + {$tag.name}{nil} {if not isLast($tag)},{sp}{/if} {/foreach}

@@ -26,7 +26,7 @@

View content from {foreach $month in $months} - {$month}{nil} + {$month}{nil} {if not isLast($month)},{sp}{/if} {/foreach}

diff --git a/themes/hyde/post.tmpl b/themes/hyde/post.tmpl index 8400fcb..d66e8e9 100644 --- a/themes/hyde/post.tmpl +++ b/themes/hyde/post.tmpl @@ -6,7 +6,7 @@
{\n} {if $post.tags} Tagged as {foreach $tag in $post.tags} - {$tag.name}{nil} + {$tag.name}{nil} {if not isLast($tag)},{sp}{/if} {/foreach} {/if} @@ -21,7 +21,7 @@ {$post.text |noAutoescape}
{\n}
{\n} - {if $prev} Previous
{/if}{\n} - {if $next} Next
{/if}{\n} + {if $prev} Previous
{/if}{\n} + {if $next} Next
{/if}{\n}
{\n} {/template} diff --git a/themes/readable/index.tmpl b/themes/readable/index.tmpl index 8abe85f..5cf5514 100644 --- a/themes/readable/index.tmpl +++ b/themes/readable/index.tmpl @@ -4,7 +4,7 @@

{$index.title}

{foreach $obj in $index.content}
-

{$obj.title}

+

{$obj.title}

posted on {$obj.date}

{$obj.text |noAutoescape}
@@ -13,7 +13,7 @@

This blog covers {foreach $tag in $tags} - {$tag.name}{nil} + {$tag.name}{nil} {if not isLast($tag)},{sp}{/if} {/foreach}

@@ -23,7 +23,7 @@

View content from {foreach $month in $months} - {$month}{nil} + {$month}{nil} {if not isLast($month)},{sp}{/if} {/foreach}

diff --git a/themes/readable/post.tmpl b/themes/readable/post.tmpl index 15843f1..76bb24a 100644 --- a/themes/readable/post.tmpl +++ b/themes/readable/post.tmpl @@ -6,7 +6,7 @@

{if $post.tags} Tagged as {foreach $tag in $post.tags} - {$tag.name}{nil} + {$tag.name}{nil} {if not isLast($tag)},{sp}{/if} {/foreach} {/if} @@ -20,8 +20,8 @@ {$post.text |noAutoescape}

{\n} {/template} diff --git a/themes/rss.tmpl b/themes/rss.tmpl index a21682e..bcd4460 100644 --- a/themes/rss.tmpl +++ b/themes/rss.tmpl @@ -13,10 +13,10 @@ {foreach $post in $content.content} {$post.title} - {$config.domain}/posts/{$post.slug}.{$config.pageExt} + {$config.domain}/{$post.path} {$post.date} {$config.author} - {$config.domain}/posts/{$post.slug}.{$config.pageExt} + {$config.domain}/{$post.path} {foreach $tag in $post.tags} {/foreach}