getnikola/nikola — pull request #1554 by felixfontein (2014-12-27 19:25:57+00:00)
Title: Refactoring indexes path/link generation for possible extensions

Hi,
I started refactoring the link and path generation for indexes (```Nikola.generic_index_renderer```). I took a slightly different approach as in #1548, namely I extended the functionality in utils.py. The current "main" function is ```adjust_name_for_index_path_list```, which works on a list of path elements (something path handlers work on, too); there are two helpers to apply this to existing links and paths (by first splitting the given path/link, applying ```adjust_name_for_index_path_list```, and then recombining the rest).

I als added some more arguments to the functions (including the callable objects to be provided to ```Nikola.generic_index_renderer```), so that later changes (using /page/2/ instead of index-2.html, where 2 in /page/2/ is not the index i, but the logical page number displayed on the page itself!) can easily be added later on. For example, using /page/2/ in case ```PRETTY_URLS == True``` can be achieved by replacing ```adjust_name_for_index_path_list``` with:
```
def adjust_name_for_index_path_list(path_list, i, displayed_i, site, force_addition=False):
index_file = site.config["INDEX_FILE"]
if i or force_addition:
if force_addition and not i:
i = 0
extension = '.' + index_file.split('.')[-1]
if len(path_list) == 0 or not path_list[-1].endswith(extension):
path_list.append(index_file)
if site.config["PRETTY_URLS"] and path_list[-1] == index_file:
path_list[-1] = 'page'
path_list.append(str(displayed_i))
path_list.append(index_file)
else:
path_list[-1] = path_list[-1][:-len(extension)] + '-{0}'.format(i) + extension
return path_list
```
Cheers,
Felix