Relative URLs done right.

This commit is contained in:
Brit Butler 2012-08-21 22:19:36 -04:00
parent 3c0b0a05c1
commit 492a36e781
3 changed files with 14 additions and 12 deletions

View file

@ -13,14 +13,12 @@
(defun taglinks (&optional tags) (defun taglinks (&optional tags)
"Generate links to all the tag indices or those in TAGS." "Generate links to all the tag indices or those in TAGS."
(loop for tag in (or tags (sort (all-tags) #'string<)) (loop for tag in (or tags (sort (all-tags) #'string<))
collect (list :url (format nil "~a/tag/~a.html" (domain *config*) tag) collect (list :url (format nil "tag/~a.html" tag) :name tag)))
:name tag)))
(defun monthlinks () (defun monthlinks ()
"Generate links to all the month indices." "Generate links to all the month indices."
(loop for month in (sort (all-months) #'string<) (loop for month in (sort (all-months) #'string<)
collect (list :url (format nil "~a/date/~a.html" (domain *config*) month) collect (list :url (format nil "date/~a.html" month) :name month)))
:name month)))
(defun get-month (timestamp) (defun get-month (timestamp)
"Extract the YYYY-MM portion of TIMESTAMP." "Extract the YYYY-MM portion of TIMESTAMP."
@ -30,11 +28,13 @@
"Sort POSTS in reverse chronological order." "Sort POSTS in reverse chronological order."
(sort posts #'string> :key #'post-date)) (sort posts #'string> :key #'post-date))
(defun write-index (posts filename title &optional prev next) (defun write-index (posts filename title &key prev next (relative t))
"Write out the HTML for POSTS to FILENAME.html." "Write out the HTML for POSTS to FILENAME.html."
(let ((content (loop for post in posts (let ((content (loop for post in posts
collect (list :url (format nil "~a/posts/~a" collect (list :url (if relative
(domain *config*) (post-url post)) (format nil "../posts/~a" (post-url post))
(format nil "~a/posts/~a"
(domain *config*) (post-url post)))
:title (post-title post) :title (post-title post)
:date (post-date post) :date (post-date post)
:content (render-content (post-content post) :content (render-content (post-content post)
@ -43,6 +43,7 @@
(funcall (theme-fn "INDEX") (funcall (theme-fn "INDEX")
(list :taglinks (taglinks) (list :taglinks (taglinks)
:monthlinks (monthlinks) :monthlinks (monthlinks)
:siteroot (domain *config*)
:title title :title title
:posts content :posts content
:prev (and prev (format nil "~d.html" prev)) :prev (and prev (format nil "~d.html" prev))
@ -56,8 +57,9 @@
(let ((posts (by-date (hash-table-values *posts*)))) (let ((posts (by-date (hash-table-values *posts*))))
(loop for i = 1 then (1+ i) (loop for i = 1 then (1+ i)
do (write-index (by-20 posts i) (format nil "~d.html" i) "Recent Posts" do (write-index (by-20 posts i) (format nil "~d.html" i) "Recent Posts"
(and (plusp (1- i)) (1- i)) :prev (and (plusp (1- i)) (1- i))
(and (< (* i 20) (length posts)) (1+ i))) :next (and (< (* i 20) (length posts)) (1+ i))
:relative nil)
until (> (* i 20) (length posts)))))) until (> (* i 20) (length posts))))))
(defun render-by-tag () (defun render-by-tag ()

View file

@ -16,7 +16,7 @@
<div id="tagsoup"> <div id="tagsoup">
<p>This blog covers <p>This blog covers
{foreach $taglink in $taglinks} {foreach $taglink in $taglinks}
<a href="{$taglink.url |noAutoescape}">{$taglink.name}</a> <a href="{$siteroot}/{$taglink.url |noAutoescape}">{$taglink.name}</a>
{if not isLast($taglink)}, {/if} {if not isLast($taglink)}, {/if}
{/foreach} {/foreach}
</div> </div>
@ -25,7 +25,7 @@
<div id="monthsoup"> <div id="monthsoup">
<p>View posts from <p>View posts from
{foreach $monthlink in $monthlinks} {foreach $monthlink in $monthlinks}
<a href="{$monthlink.url |noAutoescape}">{$monthlink.name}</a> <a href="{$siteroot}/{$monthlink.url |noAutoescape}">{$monthlink.name}</a>
{if not isLast($monthlink)}, {/if} {if not isLast($monthlink)}, {/if}
{/foreach} {/foreach}
</div> </div>

View file

@ -5,7 +5,7 @@
<h1 class="title">{$title}</h1>{\n} <h1 class="title">{$title}</h1>{\n}
<div class="tags">{\n} <div class="tags">{\n}
Tagged as {foreach $tag in $tags} Tagged as {foreach $tag in $tags}
<a href="{$tag.url |noAutoescape}">{$tag.name}</a> <a href="../{$tag.url |noAutoescape}">{$tag.name}</a>
{if not isLast($tag)}, {/if} {if not isLast($tag)}, {/if}
{/foreach} {/foreach}
</div>{\n} </div>{\n}