Skip to content

Commit

Permalink
Ensuring that generic_index_render always works fine with an empty po…
Browse files Browse the repository at this point in the history
…st list.
  • Loading branch information
felixfontein committed Dec 8, 2016
1 parent 2038779 commit 6fad65a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt
Expand Up @@ -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
--------
Expand Down
6 changes: 4 additions & 2 deletions nikola/nikola.py
Expand Up @@ -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
Expand All @@ -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()
Expand Down

0 comments on commit 6fad65a

Please sign in to comment.