Skip to content
Permalink
Browse files
Ensuring that generic_index_render always works fine with an empty po…
…st list.
  • Loading branch information
felixfontein committed Dec 8, 2016
1 parent 2038779 commit 6fad65a7c14893ff795297346d7de44b88b45201
Showing with 7 additions and 2 deletions.
  1. +3 −0 CHANGES.txt
  2. +4 −2 nikola/nikola.py
@@ -8,6 +8,9 @@ Bugfixes
as ``global_data`` (Issue #2488)
* Don't crash if plugins is a file (Issue #2539)
* Don't mangle bare ``#`` links (Issue #2553)
* ``generic_index_renderer`` now always produces output. It previously
did not when the post list was empty and ``INDEXES_STATIC == False``.
(via Issue #2579)

Features
--------
@@ -2404,8 +2404,11 @@ def generic_index_renderer(self, lang, posts, indexes_title, template_name, cont
while posts:
lists.append(posts[:kw["index_display_post_count"]])
posts = posts[kw["index_display_post_count"]:]
if not lists:
lists.append([])
num_pages = len(lists)
displayed_page_numbers = [utils.get_displayed_page_number(i, num_pages, self) for i in range(num_pages or 1)]
assert num_pages >= 1
displayed_page_numbers = [utils.get_displayed_page_number(i, num_pages, self) for i in range(num_pages)]
page_links = [page_link(i, page_number, num_pages, False) for i, page_number in enumerate(displayed_page_numbers)]
if kw['show_index_page_navigation']:
# Since the list displayed_page_numbers is not necessarily
@@ -2414,7 +2417,6 @@ def generic_index_renderer(self, lang, posts, indexes_title, template_name, cont
# via a map. This allows to not replicate the logic of
# utils.get_displayed_page_number() here.
temp_map = {page_number - 1: link for page_number, link in zip(displayed_page_numbers, page_links)}
# Note that len(temp_map) >= num_pages.
page_links_context = [temp_map[i] for i in range(num_pages)]
for i, post_list in enumerate(lists):
context = context_source.copy()

0 comments on commit 6fad65a

Please sign in to comment.