Add blog sibling nav links to blog entries

This commit is contained in:
Noah 2014-04-19 21:28:35 -07:00
parent 978928c97e
commit e2f7495add
3 changed files with 39 additions and 0 deletions

View File

@ -65,6 +65,21 @@ def entry(fid):
# Count the comments for this post # Count the comments for this post
post["comment_count"] = Comment.count_comments("blog-{}".format(post_id)) 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 g.info["post"] = post
return template("blog/entry.html") return template("blog/entry.html")

View File

@ -6,6 +6,9 @@
<a href="{{ url_for('blog.entry', fid=post['fid']) }}" class="blog-title-index"> <a href="{{ url_for('blog.entry', fid=post['fid']) }}" class="blog-title-index">
{{ post["subject"] }} {{ post["subject"] }}
</a><p> </a><p>
{% else %}
{% include "blog/sibling-links.html" %}
<p>
{% endif %} {% endif %}
<div class="blog-author"> <div class="blog-author">
@ -67,6 +70,9 @@
<p> <p>
{% if from != "index" %} {% if from != "index" %}
{% include "blog/sibling-links.html" %}
<p>
{{ include_page("comment.partial_index", {{ include_page("comment.partial_index",
thread="blog-"+post["post_id"]|string, thread="blog-"+post["post_id"]|string,
subject=post["subject"], subject=post["subject"],

View File

@ -0,0 +1,18 @@
{# Older/Newer links #}
{% if post["siblings"][0] or post["siblings"][1] %}
<div class="right">
[
{% if post["siblings"][0] %}
<a href="{{ url_for('blog.entry', fid=post["siblings"][0]['fid']) }}">&lt; {{ post["siblings"][0]['subject'] }}</a>
{% if post["siblings"][1] %} | {% endif %}
{% endif %}
{% if post["siblings"][1] %}
<a href="{{ url_for('blog.entry', fid=post["siblings"][1]['fid']) }}">{{ post["siblings"][1]['subject'] }} &gt;</a>
{% endif %}
]
</div>
{% endif %}