Skip to content
Permalink
Browse files

Added basic page range navigation.

  • Loading branch information...
felixfontein committed Dec 5, 2016
1 parent eb1ebfb commit 4cbb8510f668277a558c466b4f10f025b71a05e1
@@ -700,6 +700,11 @@ IMAGE_FOLDERS = {'images': 'images'}
# for the full URL with the page number of the main page to the normal (shorter) main
# page URL.
# INDEXES_PRETTY_PAGE_URL = False
#
# If the following is true, a page range navigation will be inserted to indices.
# Please note that this will undo the effect of INDEXES_STATIC, as all index pages
# must be recreated whenever the number of pages changes.
# SHOW_INDEX_PAGE_NAVIGATION = False

# Color scheme to be used for code blocks. If your theme provides
# "assets/css/code.css" this is ignored.
@@ -10,11 +10,30 @@
{% endif %}
{% endblock %}

{% block page_navigation %}
<div class="page-navigation">
{% for i, link in enumerate(page_links) %}
{% if abs(i - current_page) <= 3 or i == 0 or i == page_links|length - 1 %}
{% if i == current_page %}
<span class="current-page">{{ i+1 }}</span>
{% else %}
<a href="{{ page_links[i] }}">{{ i+1 }}</a>
{% endif %}
{% elif i == current_page - 4 or i == current_page + 4 %}
<span class="ellipsis">&#x22EF;</span>
{% endif %}
{% endfor %}
</div>
{% endblock %}

{% block content %}
{% block content_header %}{% endblock %}
{% if 'main_index' in pagekind %}
{{ front_index_header }}
{% endif %}
{% if page_links %}
{{ page_navigation() }}
{% endif %}
<div class="postindex">
{% for post in posts %}
<article class="h-entry post-{{ post.meta('type') }}">
@@ -10,11 +10,30 @@
% endif
</%block>

<%block name="page_navigation">
<div class="page-navigation">
% for i, link in enumerate(page_links):
% if abs(i - current_page) <= 3 or i == 0 or i == len(page_links) - 1:
% if i == current_page:
<span class="current-page">${i+1}</span>
% else:
<a href="${page_links[i]}">${i+1}</a>
% endif
% elif i == current_page - 4 or i == current_page + 4:
<span class="ellipsis">&#x22EF;</span>
% endif
% endfor
</div>
</%block>

<%block name="content">
<%block name="content_header"></%block>
% if 'main_index' in pagekind:
${front_index_header}
% endif
% if page_links:
${page_navigation()}
% endif
<div class="postindex">
% for post in posts:
<article class="h-entry post-${post.meta('type')}">
@@ -554,6 +554,7 @@ def __init__(self, **config):
'SASS_OPTIONS': [],
'SEARCH_FORM': '',
'SHOW_BLOG_TITLE': True,
'SHOW_INDEX_PAGE_NAVIGATION': False,
'SHOW_SOURCELINK': True,
'SHOW_UNTRANSLATED_POSTS': True,
'SLUG_AUTHOR_PATH': True,
@@ -2360,6 +2361,7 @@ def generic_index_renderer(self, lang, posts, indexes_title, template_name, cont
kw['generate_atom'] = self.config["GENERATE_ATOM"]
kw['feed_links_append_query'] = self.config["FEED_LINKS_APPEND_QUERY"]
kw['currentfeed'] = None
kw['show_index_page_navigation'] = self.config['SHOW_INDEX_PAGE_NAVIGATION']

# Split in smaller lists
lists = []
@@ -2374,11 +2376,16 @@ def generic_index_renderer(self, lang, posts, indexes_title, template_name, cont
lists.append(posts[:kw["index_display_post_count"]])
posts = posts[kw["index_display_post_count"]:]
num_pages = len(lists)
displayed_page_numbers = [utils.get_displayed_page_number(i, num_pages, self) for i in range(max(num_pages, 1))]
page_links = [page_link(i, displayed_page_numbers[i], num_pages, False) for i in range(max(num_pages, 1))]
if kw['show_index_page_navigation']:
map = {page_number - 1: link for page_number, link in zip(displayed_page_numbers, page_links)}
page_links_context = [map[i] for i in range(num_pages)]
for i, post_list in enumerate(lists):
context = context_source.copy()
if 'pagekind' not in context:
context['pagekind'] = ['index']
ipages_i = utils.get_displayed_page_number(i, num_pages, self)
ipages_i = displayed_page_numbers[i]
if kw["indexes_pages"]:
indexes_pages = kw["indexes_pages"] % ipages_i
else:
@@ -2414,20 +2421,18 @@ def generic_index_renderer(self, lang, posts, indexes_title, template_name, cont
if i < num_pages - 1:
nextlink = i + 1
if prevlink is not None:
context["prevlink"] = page_link(prevlink,
utils.get_displayed_page_number(prevlink, num_pages, self),
num_pages, False)
context["prevfeedlink"] = page_link(prevlink,
utils.get_displayed_page_number(prevlink, num_pages, self),
context["prevlink"] = page_links[prevlink]
context["prevfeedlink"] = page_link(prevlink, displayed_page_numbers[prevlink],
num_pages, False, extension=".atom")
if nextlink is not None:
context["nextlink"] = page_link(nextlink,
utils.get_displayed_page_number(nextlink, num_pages, self),
num_pages, False)
context["nextfeedlink"] = page_link(nextlink,
utils.get_displayed_page_number(nextlink, num_pages, self),
context["nextlink"] = page_links[nextlink]
context["nextfeedlink"] = page_link(nextlink, displayed_page_numbers[nextlink],
num_pages, False, extension=".atom")
context["permalink"] = page_link(i, ipages_i, num_pages, False)
context['show_index_page_navigation'] = kw['show_index_page_navigation']
if kw['show_index_page_navigation']:
context['page_links'] = page_links_context
context['current_page'] = ipages_i - 1
context["permalink"] = page_links[i]
output_name = os.path.join(kw['output_folder'], page_path(i, ipages_i, num_pages, False))
task = self.generic_post_list_renderer(
lang,
@@ -2471,8 +2476,8 @@ def generic_index_renderer(self, lang, posts, indexes_title, template_name, cont

if kw["indexes_pages_main"] and kw['indexes_prety_page_url'](lang):
# create redirection
output_name = os.path.join(kw['output_folder'], page_path(0, utils.get_displayed_page_number(0, num_pages, self), num_pages, True))
link = page_link(0, utils.get_displayed_page_number(0, num_pages, self), num_pages, False)
output_name = os.path.join(kw['output_folder'], page_path(0, displayed_page_numbers[0], num_pages, True))
link = page_links[0]
yield utils.apply_filters({
'basename': basename,
'name': output_name,

0 comments on commit 4cbb851

Please sign in to comment.
You can’t perform that action at this time.