Add blog sibling nav links to blog entries

pull/2/head
Noah 2014-04-19 21:28:35 -07:00
ebeveyn 978928c97e
işleme e2f7495add
3 değiştirilmiş dosya ile 39 ekleme ve 0 silme

Dosyayı Görüntüle

@ -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")

Dosyayı Görüntüle

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

Dosyayı Görüntüle

@ -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 %}