Merge pull request #150 from borgar/limit-feeds-to-n

Configurable feeds: add an option to reduce the number of items in the feed
This commit is contained in:
Alexis Metaireau 2011-08-03 01:58:46 -07:00
commit 79e675b911
3 changed files with 8 additions and 2 deletions

View file

@ -115,6 +115,8 @@ Setting name (default value) what does it do?
`TAG_FEED` (``None``, ie no tag feed) relative url to output the tags atom feed. It should
be defined using a "%s" matchin the tag name
`TAG_FEED_RSS` (``None``, ie no RSS tag feed) relative url to output the tag RSS feed
`FEED_MAX_ITEMS` Maximum number of items allowed in a feed. Feeds are
unrestricted by default.
================================================ =====================================================
.. [2] %s is the name of the category.

View file

@ -15,6 +15,7 @@ _DEFAULT_CONFIG = {'PATH': None,
'FEED': 'feeds/all.atom.xml',
'CATEGORY_FEED': 'feeds/%s.atom.xml',
'TRANSLATION_FEED': 'feeds/all-%s.atom.xml',
'FEED_MAX_ITEMS': '',
'SITENAME': 'A Pelican Blog',
'DISPLAY_PAGES_ON_MENU': True,
'PDF_GENERATOR': False,

View file

@ -58,8 +58,11 @@ class Writer(object):
feed = self._create_new_feed(feed_type, context)
for item in elements:
self._add_item_to_the_feed(feed, item)
max_items = len(elements)
if self.settings['FEED_MAX_ITEMS']:
max_items = min(self.settings['FEED_MAX_ITEMS'], max_items)
for i in xrange(max_items):
self._add_item_to_the_feed(feed, elements[i])
if filename:
complete_path = os.path.join(self.output_path, filename)