From e2f7495addae0a355140dd117f3c857cb69e7714 Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Sat, 19 Apr 2014 21:28:35 -0700 Subject: [PATCH] Add blog sibling nav links to blog entries --- rophako/modules/blog.py | 15 +++++++++++++++ rophako/www/blog/entry.inc.html | 6 ++++++ rophako/www/blog/sibling-links.html | 18 ++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 rophako/www/blog/sibling-links.html diff --git a/rophako/modules/blog.py b/rophako/modules/blog.py index 59e2d62..fecb08c 100644 --- a/rophako/modules/blog.py +++ b/rophako/modules/blog.py @@ -65,6 +65,21 @@ def entry(fid): # Count the comments for this post post["comment_count"] = Comment.count_comments("blog-{}".format(post_id)) + # Inject information about this post's siblings. + index = Blog.get_index() + siblings = [None, None] # previous, next + sorted_ids = map(lambda y: int(y), sorted(index.keys(), key=lambda x: index[x]["time"], reverse=True)) + for i in range(0, len(sorted_ids)): + if sorted_ids[i] == post_id: + # Found us! + if i > 0: + # We have an older post. + siblings[0] = index[ str(sorted_ids[i-1]) ] + if i < len(sorted_ids) - 1: + # We have a newer post. + siblings[1] = index[ str(sorted_ids[i+1]) ] + post["siblings"] = siblings + g.info["post"] = post return template("blog/entry.html") diff --git a/rophako/www/blog/entry.inc.html b/rophako/www/blog/entry.inc.html index 3778b38..8f43672 100644 --- a/rophako/www/blog/entry.inc.html +++ b/rophako/www/blog/entry.inc.html @@ -6,6 +6,9 @@ {{ post["subject"] }}

+ {% else %} + {% include "blog/sibling-links.html" %} +

{% endif %}

@@ -67,6 +70,9 @@

{% if from != "index" %} + {% include "blog/sibling-links.html" %} +

+ {{ include_page("comment.partial_index", thread="blog-"+post["post_id"]|string, subject=post["subject"], diff --git a/rophako/www/blog/sibling-links.html b/rophako/www/blog/sibling-links.html new file mode 100644 index 0000000..e1d0ac1 --- /dev/null +++ b/rophako/www/blog/sibling-links.html @@ -0,0 +1,18 @@ +{# Older/Newer links #} + +{% if post["siblings"][0] or post["siblings"][1] %} +

+ [ + {% if post["siblings"][0] %} + < {{ post["siblings"][0]['subject'] }} + + {% if post["siblings"][1] %} | {% endif %} + {% endif %} + + {% if post["siblings"][1] %} + {{ post["siblings"][1]['subject'] }} > + {% endif %} + + ] +
+{% endif %} \ No newline at end of file