Skip to content

Commit

Permalink
Providing additional argument alternative_path to index and Atom feed…
Browse files Browse the repository at this point in the history
… path handlers for taxonomy plugins.
  • Loading branch information
felixfontein committed Dec 11, 2016
1 parent 641eacd commit 429d4cb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
16 changes: 10 additions & 6 deletions nikola/plugins/misc/taxonomies_classifier.py
Expand Up @@ -205,7 +205,7 @@ def _compute_number_of_pages(filtered_posts, posts_count):
"""Given a list of posts and the maximal number of posts per page, computes the number of pages needed."""
return min(1, (len(filtered_posts) + posts_count - 1) // posts_count)

def _postprocess_path(self, path, lang, append_index='auto', dest_type='page', page_info=None):
def _postprocess_path(self, path, lang, append_index='auto', dest_type='page', page_info=None, alternative_path=False):
"""Postprocess a generated path.
Takes the path `path` for language `lang`, and postprocesses it.
Expand All @@ -218,11 +218,15 @@ def _postprocess_path(self, path, lang, append_index='auto', dest_type='page', p
`site.config['INDEX_FILE']` depending on `dest_type`, which can be
`'feed'`, `'rss'` or `'page'`.
Finally, if `dest_type` is `'page'`, `page_info` can be `None` or a tuple
If `dest_type` is `'page'`, `page_info` can be `None` or a tuple
of two integers: the page number and the number of pages. This will
be used to append the correct page number by calling
`utils.adjust_name_for_index_path_list` and
`utils.get_displayed_page_number`.
If `alternative_path` is set to `True`, `utils.adjust_name_for_index_path_list`
is called with `force_addition=True`, resulting in an alternative path for the
first page of an index or Atom feed.
"""
# Forcing extension for Atom feeds and RSS feeds
force_extension = None
Expand All @@ -249,7 +253,7 @@ def _postprocess_path(self, path, lang, append_index='auto', dest_type='page', p
page_info[0],
utils.get_displayed_page_number(page_info[0], page_info[1], self.site),
lang,
self.site, extension=force_extension)
self.site, force_addition=alternative_path, extension=force_extension)
return result

@staticmethod
Expand All @@ -269,7 +273,7 @@ def _taxonomy_index_path(self, name, lang, taxonomy):
path, append_index, _ = self._parse_path_result(result)
return self._postprocess_path(path, lang, append_index=append_index, dest_type='list')

def _taxonomy_path(self, name, lang, taxonomy, dest_type='page', page=None):
def _taxonomy_path(self, name, lang, taxonomy, dest_type='page', page=None, alternative_path=False):
"""Return path to a classification."""
if taxonomy.has_hierarchy:
result = taxonomy.get_path(taxonomy.extract_hierarchy(name), lang, dest_type=dest_type)
Expand All @@ -291,9 +295,9 @@ def _taxonomy_path(self, name, lang, taxonomy, dest_type='page', page=None):
page_info = (page, number_of_pages)
return self._postprocess_path(path, lang, append_index=append_index, dest_type=dest_type, page_info=page_info)

def _taxonomy_atom_path(self, name, lang, taxonomy, page=None):
def _taxonomy_atom_path(self, name, lang, taxonomy, page=None, alternative_path=False):
"""Return path to a classification Atom feed."""
return self._taxonomy_path(name, lang, taxonomy, dest_type='feed', page=page)
return self._taxonomy_path(name, lang, taxonomy, dest_type='feed', page=page, alternative_path=alternative_path)

def _taxonomy_rss_path(self, name, lang, taxonomy):
"""Return path to a classification RSS feed."""
Expand Down
4 changes: 2 additions & 2 deletions nikola/plugins/task/taxonomies.py
Expand Up @@ -230,11 +230,11 @@ def _generate_classification_page_as_index(self, taxonomy, classification, filte

def page_link(i, displayed_i, num_pages, force_addition, extension=None):
feed = "{}_atom" if extension == ".atom" else "{}"
return utils.adjust_name_for_index_link(self.site.link(feed.format(kind), classification, lang), i, displayed_i, lang, self.site, force_addition, extension)
return self.site.link(feed.format(kind), classification, lang, alternative_path=force_addition, page=i)

def page_path(i, displayed_i, num_pages, force_addition, extension=None):
feed = "{}_atom" if extension == ".atom" else "{}"
return utils.adjust_name_for_index_path(self.site.path(feed.format(kind), classification, lang), i, displayed_i, lang, self.site, force_addition, extension)
return self.site.path(feed.format(kind), classification, lang, alternative_path=force_addition, page=i)

context = copy(context)
if "pagekind" not in context:
Expand Down

0 comments on commit 429d4cb

Please sign in to comment.