Skip to content

Commit

Permalink
Improve documentation for #2627/#2630
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Jan 11, 2017
1 parent 20f2263 commit be0c864
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
15 changes: 10 additions & 5 deletions CHANGES.txt
@@ -1,12 +1,17 @@
New in master
=============

Features
--------

* It is easier to globally modify chronological post sorting.
Also, when posts are sorted for taxonomies, the post's title
is taken into account before resorting to the post's source path,
and the sorting order for title and source path are not reversed
anymore. (Issue #2627 / PR #2630)
* Sort posts chronologically with one unified function (easier to
change). (Issue #2627)
* Sort posts in the following order (most important last): source path
(A-Z), title (A-Z), date (reverse chronological order), priority
meta number (descending). (Issue #2627)

Bugfixes
--------

New in v7.8.2
=============
Expand Down
13 changes: 8 additions & 5 deletions nikola/nikola.py
Expand Up @@ -1986,15 +1986,18 @@ def create_hierarchy(cat_hierarchy, parent=None):

@staticmethod
def sort_posts_chronologically(posts, lang=None):
"""Return sorted list of posts."""
# Last tie breaker: sort by source path
"""Sort a list of posts chronologically.
This function also takes priority, title and source path into account.
"""
# Last tie breaker: sort by source path (A-Z)
posts = sorted(posts, key=lambda p: p.source_path)
# Next tie breaker: sort by title if language is given
# Next tie breaker: sort by title if language is given (A-Z)
if lang is not None:
posts = natsort.natsorted(posts, key=lambda p: p.title(lang), alg=natsort.ns.F | natsort.ns.IC)
# Next tie breaker: sort by date
# Next tie breaker: sort by date (reverse chronological order)
posts = sorted(posts, key=lambda p: p.date, reverse=True)
# Finally, sort by priority
# Finally, sort by priority meta value (descending)
posts = sorted(posts, key=lambda p: int(p.meta('priority')) if p.meta('priority') else 0, reverse=True)
# Return result
return posts
Expand Down

0 comments on commit be0c864

Please sign in to comment.