diff --git a/docs/settings.rst b/docs/settings.rst index 55740296..0c804f1c 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -260,16 +260,19 @@ posts for the month at ``posts/2011/Aug/index.html``. arrive at an appropriate archive of posts, without having to specify a page name. -====================================================== ======================================================== +====================================================== ============================================================== Setting name (followed by default value, if any) What does it do? -====================================================== ======================================================== +====================================================== ============================================================== ``ARTICLE_URL = '{slug}.html'`` The URL to refer to an article. ``ARTICLE_SAVE_AS = '{slug}.html'`` The place where we will save an article. -``ARTICLE_ORDER_BY = 'slug'`` The metadata attribute used to sort articles. By default - the articles_page.object_list template variable is - ordered by slug. If you modify this, make sure all - articles contain the attribute you specify. You can - also specify a sorting function. +``ARTICLE_ORDER_BY = 'slug'`` The metadata attribute used to sort articles. By default, + the ``articles_page.object_list`` template variable is + ordered by slug. If you modify this, make sure all + articles contain the attribute you specify. You can also + specify a "sorting" function of one argument that is used + to extract a comparison key from each article. For example, + sorting by title without using the built-in functionality + would use the function ``operator.attrgetter('title')``. ``ARTICLE_LANG_URL = '{slug}-{lang}.html'`` The URL to refer to an article which doesn't use the default language. ``ARTICLE_LANG_SAVE_AS = '{slug}-{lang}.html'`` The place where we will save an article which @@ -285,13 +288,16 @@ Setting name (followed by default value, if any) What does it do? the same as PAGE_URL or you need to use a rewrite in your server config. -``PAGE_ORDER_BY = 'filename'`` The metadata attribute used to sort pages. By default - the PAGES template variable is ordered by filename - (path not included). Note that the option 'filename' - is a special option supported in the source code. If - you modify this settings, make sure all pages contain - the attribute you specify. You can also specify a - sorting function. +``PAGE_ORDER_BY = 'basename'`` The metadata attribute used to sort pages. By default + the ``PAGES`` template variable is ordered by basename + (i.e., path not included). Note that the option ``'basename'`` + is a special option supported in the source code. If + you modify this setting, make sure all pages contain + the attribute you specify. You can also specify a "sorting" + function of one argument that is used to extract a comparison + key from each page. For example, the basename function looks + similar to + ``lambda x: os.path.basename(getattr(x, 'source_path', ''))``. ``PAGE_LANG_URL = 'pages/{slug}-{lang}.html'`` The URL we will use to link to a page which doesn't use the default language. ``PAGE_LANG_SAVE_AS = 'pages/{slug}-{lang}.html'`` The location we will save the page which doesn't @@ -309,7 +315,7 @@ Setting name (followed by default value, if any) What does it do? non-alphanumerics when generating slugs. Specified as a list of 2-tuples of ``(from, to)`` which are applied in order. -====================================================== ======================================================== +====================================================== ============================================================== .. note:: diff --git a/pelican/utils.py b/pelican/utils.py index ecdf5e0d..076c41ea 100644 --- a/pelican/utils.py +++ b/pelican/utils.py @@ -465,17 +465,13 @@ def process_translations(content_list, order_by=None): a.translations = [x for x in items if x != a] if order_by: - if hasattr(order_by, '__call__'): + if callable(order_by): try: index.sort(key=order_by) - except: - if hasattr(order_by, 'func_name'): - logger.error("Error sorting with function %s" % order_by.func_name) - else: - logger.error("Error sorting with function %r" % order_by) - elif order_by == 'filename': - index.sort(key=lambda x:os.path.basename( - x.source_path or '')) + except Exception: + logger.error('Error sorting with function {}'.format(order_by)) + elif order_by == 'basename': + index.sort(key=lambda x: os.path.basename(x.source_path or '')) elif order_by != 'slug': index.sort(key=attrgetter(order_by))