I run a slightly-tweaked 0.7.
At the bottom of my _templates/permapage.mako, I have:
% if prev_post or next_post:
<p class="prev_next">
% if prev_post:
<a href="${prev_post}">« Previous Post</a>
% endif
% if prev_post and next_post:
|
% endif
% if next_post:
<a href="${next_post}">Next Post »</a>
% endif
</p>
% endif
Then in my _controllers/blog/permapage.py, my write_permapages looks
like this - the important bit is conditionally adding the
next/previous permalinks to the env dictionary:
def write_permapages():
"Write blog posts to their permalink locations"
site_re = re.compile(bf.config.site.url, re.IGNORECASE)
num_posts = len(blog.posts)
for i, post in enumerate(blog.posts):
if post.permalink:
path = site_re.sub("", post.permalink)
blog.logger.info("Writing permapage for post: {0}".format(path))
else:
#Permalinks MUST be specified. No permalink, no page.
blog.logger.info("Post has no permalink: {0}".format(post.title))
continue
env = {
"post": post,
"posts": blog.posts,
"next_post": None,
"prev_post": None
}
#Find the next and previous posts chronologically
if i < num_posts -1:
env['prev_post'] = site_re.sub("", blog.posts[i + 1].permalink)
if i > 0:
env['next_post'] = site_re.sub("", blog.posts[i - 1].permalink)
bf.writer.materialize_template(
"permapage.mako", bf.util.path_join(path, "index.html"), env)
Hope that helps!
--
Mike Pirnat
mpi...@gmail.com
http://mike.pirnat.com/
I do almost the same, but here I give template whole post object (just
strip .permalink from above). This way I can use actual titles in my
permapage.mako:
%if prev_post or next_post:
<div class="entrypaging">
##Prev and next entries:
<br/>
%if prev_post:
<span class="entrypaging_left">
«
<a href="${prev_post.permapath()}">${prev_post.title}</a>
</span>
%endif
<span class="epicon">|</span>
%if next_post:
<span class="entrypaging_right">
<a href="${next_post.permapath()}">${next_post.title}</a>
»
</span>
%endif
</div>
%endif
Whether to use titles or Prev/Next is of course a matter of taste, but
such parametrization gives more templating freedom…
PS In general it is fairly easy to patch elements of blog controller
to provide more data to templates and to generate additional pages
(like extra indexes based on different criteria).