From d0ec18f4dbd623c55bdf4928ee7c363f699ef696 Mon Sep 17 00:00:00 2001 From: Alexis Metaireau Date: Tue, 1 Feb 2011 01:57:39 +0000 Subject: [PATCH] Add the ability to sort categories. generator.categories is now a list of (category, articles) instead of a dict. This is to avoid using ordered dicts that have been introduces in python 2.7, so we stay as much as possible compatible with older versions. This fixes #62. Thanks to Bruno for the report. --- THANKS | 1 + docs/settings.rst | 2 ++ pelican/generators.py | 10 +++++++--- pelican/settings.py | 1 + samples/pelican.conf.py | 1 + 5 files changed, 12 insertions(+), 3 deletions(-) diff --git a/THANKS b/THANKS index 0604e5db..aaee40bc 100644 --- a/THANKS +++ b/THANKS @@ -10,3 +10,4 @@ bugs or giving ideas. Thanks to them ! - David Kulak - Arnaud Bos - nblock (Florian) +- Bruno Bord diff --git a/docs/settings.rst b/docs/settings.rst index e59d1b5b..f64b102b 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -54,6 +54,8 @@ Setting name what it does ? documents. You will need to install `rst2pdf`. `REVERSE_ARCHIVE_ORDER` Reverse the archives order. (True makes it in descending order: the newer first) +`REVERSE_CATEGORY_ORDER` Reverse the category order. (True makes it in + descending order, default is alphabetically) `SITEURL` base URL of your website. `SITENAME` Your site name, `STATIC_PATHS` The static paths you want to have accessible on the diff --git a/pelican/generators.py b/pelican/generators.py index 05620e69..a2ea3593 100755 --- a/pelican/generators.py +++ b/pelican/generators.py @@ -94,7 +94,7 @@ class ArticlesGenerator(Generator): writer.write_feed(self.articles, self.context, self.settings['FEED_RSS'], feed_type='rss') - for cat, arts in self.categories.items(): + for cat, arts in self.categories: arts.sort(key=attrgetter('date'), reverse=True) writer.write_feed(arts, self.context, self.settings['CATEGORY_FEED'] % cat) @@ -149,9 +149,9 @@ class ArticlesGenerator(Generator): write('tag/%s.html' % tag, templates['tag'], self.context, tag=tag, articles=articles) - for cat in self.categories: + for cat, articles in self.categories: write('category/%s.html' % cat, templates['category'], self.context, - category=cat, articles=self.categories[cat]) + category=cat, articles=articles) def generate_context(self): """change the context""" @@ -200,6 +200,10 @@ class ArticlesGenerator(Generator): self.dates.sort(key=attrgetter('date'), reverse=self.context['REVERSE_ARCHIVE_ORDER']) # and generate the output :) + + # order the categories per name + self.categories = list(self.categories.items()) + self.categories.sort(reverse=self.settings.get('REVERSE_CATEGORY_ORDER')) self._update_context(('articles', 'dates', 'tags', 'categories')) def generate_output(self, writer): diff --git a/pelican/settings.py b/pelican/settings.py index 2178c5ca..3fd0a6da 100644 --- a/pelican/settings.py +++ b/pelican/settings.py @@ -18,6 +18,7 @@ _DEFAULT_CONFIG = {'PATH': None, 'FALLBACK_ON_FS_DATE': True, 'CSS_FILE': 'main.css', 'REVERSE_ARCHIVE_ORDER': False, + 'REVERSE_CATEGORY_ORDER': False, 'KEEP_OUTPUT_DIRECTORY': False, 'CLEAN_URLS': False, # use /blah/ instead /blah.html in urls 'RELATIVE_URLS': True, diff --git a/samples/pelican.conf.py b/samples/pelican.conf.py index daf1d20d..6cb869d8 100755 --- a/samples/pelican.conf.py +++ b/samples/pelican.conf.py @@ -6,6 +6,7 @@ SITEURL = 'http://blog.notmyidea.org' GITHUB_URL = 'http://github.com/ametaireau/' DISQUS_SITENAME = "blog-notmyidea" PDF_GENERATOR = False +REVERSE_CATEGORY_ORDER = True LINKS = (('Biologeek', 'http://biologeek.org'), ('Filyb', "http://filyb.info/"),