forked from github/pelican
Support RSS2 feeds
This commit is contained in:
parent
7d11af5630
commit
a8ac5c6268
3 changed files with 19 additions and 3 deletions
|
|
@ -109,8 +109,10 @@ Setting name what it does ?
|
|||
`STATIC_PATHS` The static paths you want to copy under "static"
|
||||
`FEED` relative url to output the feed. Default is
|
||||
`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
|
||||
`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
|
||||
the default one ('main.css')
|
||||
======================= =======================================================
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ from codecs import open
|
|||
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
from jinja2.exceptions import TemplateNotFound
|
||||
from feedgenerator import Atom1Feed
|
||||
from feedgenerator import Atom1Feed, Rss201rev2Feed
|
||||
|
||||
from pelican.settings import read_settings
|
||||
from pelican.utils import clean_output_dir
|
||||
|
|
@ -64,7 +64,8 @@ class Generator(object):
|
|||
for p in processors:
|
||||
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
|
||||
|
||||
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 output_path: where to output the file.
|
||||
: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))
|
||||
|
||||
feed = Atom1Feed(
|
||||
feed_class = Rss201rev2Feed if feed_type == 'rss' else Atom1Feed
|
||||
|
||||
feed = feed_class(
|
||||
title=context['SITENAME'],
|
||||
link=site_url,
|
||||
feed_url= "%s/%s" % (site_url, filename),
|
||||
|
|
|
|||
|
|
@ -35,11 +35,21 @@ class ArticlesProcessor(Processor):
|
|||
|
||||
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():
|
||||
arts.sort(key=attrgetter('date'), reverse=True)
|
||||
generator.generate_feed(arts, context,
|
||||
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):
|
||||
"""Generate the pages on the disk"""
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue