From fe859aa3cb4219c28ff55d6958946b49c4eed49f Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Sun, 16 Oct 2016 13:00:22 +0200 Subject: [PATCH] Improved sorting. --- nikola/plugin_categories.py | 10 +++++++++- nikola/plugins/misc/taxonomies_classifier.py | 5 ++++- nikola/plugins/task/taxonomies.py | 1 + 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/nikola/plugin_categories.py b/nikola/plugin_categories.py index 1b0bda002f..5d012e2276 100644 --- a/nikola/plugin_categories.py +++ b/nikola/plugin_categories.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. diff --git a/nikola/plugins/misc/taxonomies_classifier.py b/nikola/plugins/misc/taxonomies_classifier.py index 1791698589..5f5e4df899 100644 --- a/nikola/plugins/misc/taxonomies_classifier.py +++ b/nikola/plugins/misc/taxonomies_classifier.py @@ -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) diff --git a/nikola/plugins/task/taxonomies.py b/nikola/plugins/task/taxonomies.py index 0dcfdeb01b..ec5d0d03d0 100644 --- a/nikola/plugins/task/taxonomies.py +++ b/nikola/plugins/task/taxonomies.py @@ -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