Support RSS2 feeds

This commit is contained in:
Philippe Pepiot 2010-12-01 02:48:11 +01:00
commit a8ac5c6268
3 changed files with 19 additions and 3 deletions

View file

@ -109,8 +109,10 @@ Setting name what it does ?
`STATIC_PATHS` The static paths you want to copy under "static" `STATIC_PATHS` The static paths you want to copy under "static"
`FEED` relative url to output the feed. Default is `FEED` relative url to output the feed. Default is
`feeds/all.atom.xml` `feeds/all.atom.xml`
`FEED_RSS` relative url to output the rss feed. Default is None (no rss)
`CATEGORY_FEED` Where to put the categories feeds. default is `CATEGORY_FEED` Where to put the categories feeds. default is
`feeds/%s.atom.xml` `feeds/%s.atom.xml`
`CATEGORY_FEED_RSS` Where to put the categories rss feeds. default is None (no rss)
`CSS_FILE` To specify the CSS file you want to load, if it's not `CSS_FILE` To specify the CSS file you want to load, if it's not
the default one ('main.css') the default one ('main.css')
======================= ======================================================= ======================= =======================================================

View file

@ -4,7 +4,7 @@ from codecs import open
from jinja2 import Environment, FileSystemLoader from jinja2 import Environment, FileSystemLoader
from jinja2.exceptions import TemplateNotFound from jinja2.exceptions import TemplateNotFound
from feedgenerator import Atom1Feed from feedgenerator import Atom1Feed, Rss201rev2Feed
from pelican.settings import read_settings from pelican.settings import read_settings
from pelican.utils import clean_output_dir from pelican.utils import clean_output_dir
@ -64,7 +64,8 @@ class Generator(object):
for p in processors: for p in processors:
p.process(context, self) p.process(context, self)
def generate_feed(self, elements, context, filename=None): def generate_feed(self, elements, context, filename=None,
feed_type='atom'):
"""Generate a feed with the list of articles provided """Generate a feed with the list of articles provided
Return the feed. If no output_path or filename is specified, just return Return the feed. If no output_path or filename is specified, just return
@ -74,10 +75,13 @@ class Generator(object):
:param context: the context to get the feed metadata. :param context: the context to get the feed metadata.
:param output_path: where to output the file. :param output_path: where to output the file.
:param filename: the filename to output. :param filename: the filename to output.
:param feed_type: the feed type to use (atom or rss)
""" """
site_url = context.get('SITEURL', self._get_relative_siteurl(filename)) site_url = context.get('SITEURL', self._get_relative_siteurl(filename))
feed = Atom1Feed( feed_class = Rss201rev2Feed if feed_type == 'rss' else Atom1Feed
feed = feed_class(
title=context['SITENAME'], title=context['SITENAME'],
link=site_url, link=site_url,
feed_url= "%s/%s" % (site_url, filename), feed_url= "%s/%s" % (site_url, filename),

View file

@ -35,11 +35,21 @@ class ArticlesProcessor(Processor):
generator.generate_feed(self.articles, context, context['FEED']) generator.generate_feed(self.articles, context, context['FEED'])
if 'FEED_RSS' in context:
generator.generate_feed(self.articles, context,
context['FEED_RSS'], feed_type='rss')
for cat, arts in self.categories.items(): for cat, arts in self.categories.items():
arts.sort(key=attrgetter('date'), reverse=True) arts.sort(key=attrgetter('date'), reverse=True)
generator.generate_feed(arts, context, generator.generate_feed(arts, context,
context['CATEGORY_FEED'] % cat) context['CATEGORY_FEED'] % cat)
if 'CATEGORY_FEED_RSS' in context:
generator.generate_feed(arts, context,
context['CATEGORY_FEED_RSS'] % cat,
feed_type='rss')
def generate_pages(self, context, generator): def generate_pages(self, context, generator):
"""Generate the pages on the disk""" """Generate the pages on the disk"""