Browse Source

Add blog sibling nav links to blog entries

pull/2/head
Noah Petherbridge 8 years ago
parent
commit
e2f7495add
  1. 15
      rophako/modules/blog.py
  2. 6
      rophako/www/blog/entry.inc.html
  3. 18
      rophako/www/blog/sibling-links.html

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

6
rophako/www/blog/entry.inc.html

@ -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"],

18
rophako/www/blog/sibling-links.html

@ -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 %}
Loading…
Cancel
Save