Skip to content
Permalink
Browse files

Improved sorting.

  • Loading branch information
felixfontein committed Oct 16, 2016
1 parent 1bc2a31 commit fe859aa3cb4219c28ff55d6958946b49c4eed49f
Showing with 14 additions and 2 deletions.
  1. +9 −1 nikola/plugin_categories.py
  2. +4 −1 nikola/plugins/misc/taxonomies_classifier.py
  3. +1 −0 nikola/plugins/task/taxonomies.py
@@ -510,10 +510,18 @@ def classify(self, post, lang):
"""
raise NotImplementedError()

def sort_posts(self, posts, lang):
def sort_posts(self, posts, classification, lang):
"""Sort the given list of posts."""
pass

def sort_classifications(self, classifications, lang):
"""Sort the given list of classification strings.
For hierarchical taxonomies, the elements of the list are a single
path element of the path returned by extract_hierarchy().
"""
pass

def get_list_path(self, lang):
"""A path handler for the list of all classifications.
@@ -124,6 +124,7 @@ def _do_classification(self):
(int(p.meta('priority')) if p.meta('priority') else 0,
p.date, p.source_path))
posts.reverse()
taxonomy.sort_posts(posts, classification, lang)
posts_per_classification[classification] = posts
# Create hierarchy information
if taxonomy.has_hierarchy:
@@ -150,7 +151,9 @@ def create_hierarchy(cat_hierarchy, parent=None):
node.classification_path = [pn.name for pn in node.get_path()]
node.classification_name = taxonomy.recombine_classification_from_hierarchy(node.classification_path)
hierarchy_lookup[node.classification_name] = node
return natsort.natsorted(result, key=lambda e: e.name, alg=natsort.ns.F | natsort.ns.IC)
classifications = natsort.natsorted(result, key=lambda e: e.name, alg=natsort.ns.F | natsort.ns.IC)
taxonomy.sort_classifications(classifications)
return classifications

root_list = create_hierarchy(hierarchy)
flat_hierarchy = utils.flatten_tree_structure(root_list)
@@ -60,6 +60,7 @@ def _generate_classification_overview(self, taxonomy, lang):
classifications = natsort.natsorted([tag for tag, posts in self.site.posts_per_classification[taxonomy.classification_name][lang].items()
if len(posts) >= kw["minimum_post_count"]],
alg=natsort.ns.F | natsort.ns.IC)
taxonomy.sort_classifications(classifications)

# Set up classifications in context
context[taxonomy.metadata_name] = classifications

0 comments on commit fe859aa

Please sign in to comment.
You can’t perform that action at this time.