1
0
Fork 0
forked from github/pelican

Add a setting to limit feeds to a max number of items.

This adds FEED_MAX_ITEMS, which dictates the maximum number of items allowed in a feed.
This commit is contained in:
Borgar 2011-08-02 23:29:34 +00:00
commit cd277672d0
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)