Repository: getnikola/nikola

Issue:
Nikola build fails if SHOW_INDEX_PAGE_NAVIGATION IS True and INDEXES_STATIC is False
Steps to reproduce:
* Create a demo site with `nikola init --demo -q demo`.
* Change said values.

Full traceback (on Windows, also happens if deploying to GitLab):
```
Traceback (most recent call last):
  File "c:\users\sukil etxenike\appdata\local\programs\python\python36\lib\site-
packages\doit\doit_cmd.py", line 167, in run
    return command.parse_execute(args)
  File "c:\users\sukil etxenike\appdata\local\programs\python\python36\lib\site-
packages\doit\cmd_base.py", line 120, in parse_execute
    return self.execute(params, args)
  File "c:\users\sukil etxenike\appdata\local\programs\python\python36\lib\site-
packages\doit\cmd_base.py", line 378, in execute
    self, params, args)
  File "c:\users\sukil etxenike\appdata\local\programs\python\python36\lib\site-
packages\nikola\__main__.py", line 280, in load_tasks
    self.nikola.gen_tasks('render_site', "Task", 'Group of tasks to render the s
ite.'))
  File "c:\users\sukil etxenike\appdata\local\programs\python\python36\lib\site-
packages\doit\loader.py", line 313, in generate_tasks
    for task_dict, x_doc in flat_generator(gen_result, gen_doc):
  File "c:\users\sukil etxenike\appdata\local\programs\python\python36\lib\site-
packages\doit\loader.py", line 26, in flat_generator
    for item in gen:
  File "c:\users\sukil etxenike\appdata\local\programs\python\python36\lib\site-
packages\nikola\nikola.py", line 1910, in gen_tasks
    for task in flatten(pluginInfo.plugin_object.gen_tasks()):
  File "c:\users\sukil etxenike\appdata\local\programs\python\python36\lib\site-
packages\nikola\nikola.py", line 1905, in flatten
    for ft in flatten(t):
  File "c:\users\sukil etxenike\appdata\local\programs\python\python36\lib\site-
packages\nikola\nikola.py", line 1905, in flatten
    for ft in flatten(t):
  File "c:\users\sukil etxenike\appdata\local\programs\python\python36\lib\site-
packages\nikola\nikola.py", line 1904, in flatten
    for t in task:
  File "c:\users\sukil etxenike\appdata\local\programs\python\python36\lib\site-
packages\nikola\nikola.py", line 2464, in generic_index_renderer
    page_links_context = [temp_map[i] for i in range(num_pages)]
  File "c:\users\sukil etxenike\appdata\local\programs\python\python36\lib\site-
packages\nikola\nikola.py", line 2464, in <listcomp>
    page_links_context = [temp_map[i] for i in range(num_pages)]
KeyError: 0
`` `
Note that if `INDEXES_STATIC`is True, it builds successfully (I haven't tested if the indexes are OK though).



Discussion:

Resolving patch:
diff --git a/nikola/nikola.py b/nikola/nikola.py
--- a/nikola/nikola.py
+++ b/nikola/nikola.py
@@ -2474,7 +2474,10 @@ def generic_index_renderer(self, lang, posts, indexes_title, template_name, cont
             # form [num_pages, 1, 2, ..., num_pages - 1] -- we order it
             # 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)}
+            if not kw["indexes_pages_main"] and not kw["indexes_static"]:
+                temp_map = {page_number: link for page_number, link in zip(displayed_page_numbers, page_links)}
+            else:
+                temp_map = {page_number - 1: link for page_number, link in zip(displayed_page_numbers, page_links)}
             page_links_context = [temp_map[i] for i in range(num_pages)]
         for i, post_list in enumerate(lists):
             context = context_source.copy()
@@ -2526,7 +2529,10 @@ def generic_index_renderer(self, lang, posts, indexes_title, template_name, cont
             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
+                if not kw["indexes_pages_main"] and not kw["indexes_static"]:
+                    context['current_page'] = ipages_i
+                else:
+                    context['current_page'] = ipages_i - 1
                 context['prev_next_links_reversed'] = kw['indexes_static']
             context["permalink"] = page_links[i]
             output_name = os.path.join(kw['output_folder'], page_path(i, ipages_i, num_pages, False))


Test patch: