mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
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.
This commit is contained in:
parent
079e9f878e
commit
d0ec18f4db
5 changed files with 12 additions and 3 deletions
1
THANKS
1
THANKS
|
|
@ -10,3 +10,4 @@ bugs or giving ideas. Thanks to them !
|
||||||
- David Kulak
|
- David Kulak
|
||||||
- Arnaud Bos
|
- Arnaud Bos
|
||||||
- nblock (Florian)
|
- nblock (Florian)
|
||||||
|
- Bruno Bord
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,8 @@ Setting name what it does ?
|
||||||
documents. You will need to install `rst2pdf`.
|
documents. You will need to install `rst2pdf`.
|
||||||
`REVERSE_ARCHIVE_ORDER` Reverse the archives order. (True makes it in
|
`REVERSE_ARCHIVE_ORDER` Reverse the archives order. (True makes it in
|
||||||
descending order: the newer first)
|
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.
|
`SITEURL` base URL of your website.
|
||||||
`SITENAME` Your site name,
|
`SITENAME` Your site name,
|
||||||
`STATIC_PATHS` The static paths you want to have accessible on the
|
`STATIC_PATHS` The static paths you want to have accessible on the
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,7 @@ class ArticlesGenerator(Generator):
|
||||||
writer.write_feed(self.articles, self.context,
|
writer.write_feed(self.articles, self.context,
|
||||||
self.settings['FEED_RSS'], feed_type='rss')
|
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)
|
arts.sort(key=attrgetter('date'), reverse=True)
|
||||||
writer.write_feed(arts, self.context,
|
writer.write_feed(arts, self.context,
|
||||||
self.settings['CATEGORY_FEED'] % cat)
|
self.settings['CATEGORY_FEED'] % cat)
|
||||||
|
|
@ -149,9 +149,9 @@ class ArticlesGenerator(Generator):
|
||||||
write('tag/%s.html' % tag, templates['tag'], self.context,
|
write('tag/%s.html' % tag, templates['tag'], self.context,
|
||||||
tag=tag, articles=articles)
|
tag=tag, articles=articles)
|
||||||
|
|
||||||
for cat in self.categories:
|
for cat, articles in self.categories:
|
||||||
write('category/%s.html' % cat, templates['category'], self.context,
|
write('category/%s.html' % cat, templates['category'], self.context,
|
||||||
category=cat, articles=self.categories[cat])
|
category=cat, articles=articles)
|
||||||
|
|
||||||
def generate_context(self):
|
def generate_context(self):
|
||||||
"""change the context"""
|
"""change the context"""
|
||||||
|
|
@ -200,6 +200,10 @@ class ArticlesGenerator(Generator):
|
||||||
self.dates.sort(key=attrgetter('date'),
|
self.dates.sort(key=attrgetter('date'),
|
||||||
reverse=self.context['REVERSE_ARCHIVE_ORDER'])
|
reverse=self.context['REVERSE_ARCHIVE_ORDER'])
|
||||||
# and generate the output :)
|
# 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'))
|
self._update_context(('articles', 'dates', 'tags', 'categories'))
|
||||||
|
|
||||||
def generate_output(self, writer):
|
def generate_output(self, writer):
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ _DEFAULT_CONFIG = {'PATH': None,
|
||||||
'FALLBACK_ON_FS_DATE': True,
|
'FALLBACK_ON_FS_DATE': True,
|
||||||
'CSS_FILE': 'main.css',
|
'CSS_FILE': 'main.css',
|
||||||
'REVERSE_ARCHIVE_ORDER': False,
|
'REVERSE_ARCHIVE_ORDER': False,
|
||||||
|
'REVERSE_CATEGORY_ORDER': False,
|
||||||
'KEEP_OUTPUT_DIRECTORY': False,
|
'KEEP_OUTPUT_DIRECTORY': False,
|
||||||
'CLEAN_URLS': False, # use /blah/ instead /blah.html in urls
|
'CLEAN_URLS': False, # use /blah/ instead /blah.html in urls
|
||||||
'RELATIVE_URLS': True,
|
'RELATIVE_URLS': True,
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ SITEURL = 'http://blog.notmyidea.org'
|
||||||
GITHUB_URL = 'http://github.com/ametaireau/'
|
GITHUB_URL = 'http://github.com/ametaireau/'
|
||||||
DISQUS_SITENAME = "blog-notmyidea"
|
DISQUS_SITENAME = "blog-notmyidea"
|
||||||
PDF_GENERATOR = False
|
PDF_GENERATOR = False
|
||||||
|
REVERSE_CATEGORY_ORDER = True
|
||||||
|
|
||||||
LINKS = (('Biologeek', 'http://biologeek.org'),
|
LINKS = (('Biologeek', 'http://biologeek.org'),
|
||||||
('Filyb', "http://filyb.info/"),
|
('Filyb', "http://filyb.info/"),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue