Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Improved sorting.
  • Loading branch information
felixfontein committed Oct 16, 2016
1 parent 1bc2a31 commit fe859aa
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
10 changes: 9 additions & 1 deletion nikola/plugin_categories.py
Expand Up @@ -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.
Expand Down
5 changes: 4 additions & 1 deletion nikola/plugins/misc/taxonomies_classifier.py
Expand Up @@ -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:
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions nikola/plugins/task/taxonomies.py
Expand Up @@ -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
Expand Down

0 comments on commit fe859aa

Please sign in to comment.