mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Feed writer was refactored to allow more granular overriding of functionality.
This commit is contained in:
parent
a937424faa
commit
03104bfbc3
1 changed files with 24 additions and 15 deletions
|
|
@ -11,6 +11,25 @@ class Writer(object):
|
||||||
def __init__(self, output_path):
|
def __init__(self, output_path):
|
||||||
self.output_path = output_path
|
self.output_path = output_path
|
||||||
|
|
||||||
|
def _create_new_feed(self, feed_type, context):
|
||||||
|
feed_class = Rss201rev2Feed if feed_type == 'rss' else Atom1Feed
|
||||||
|
feed = feed_class(
|
||||||
|
title=context['SITENAME'],
|
||||||
|
link=self.site_url,
|
||||||
|
feed_url=self.feed_url,
|
||||||
|
description=context.get('SITESUBTITLE', ''))
|
||||||
|
return feed
|
||||||
|
|
||||||
|
|
||||||
|
def _add_item_to_the_feed(self, feed, item):
|
||||||
|
feed.add_item(
|
||||||
|
title=item.title,
|
||||||
|
link='%s/%s' % (self.site_url, item.url),
|
||||||
|
description=item.content,
|
||||||
|
categories=item.tags if hasattr(item, 'tags') else None,
|
||||||
|
author_name=getattr(item, 'author', 'John Doe'),
|
||||||
|
pubdate=item.date)
|
||||||
|
|
||||||
def write_feed(self, elements, context, filename=None, feed_type='atom'):
|
def write_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
|
||||||
|
|
||||||
|
|
@ -23,23 +42,13 @@ class Writer(object):
|
||||||
:param filename: the filename to output.
|
:param filename: the filename to output.
|
||||||
:param feed_type: the feed type to use (atom or rss)
|
:param feed_type: the feed type to use (atom or rss)
|
||||||
"""
|
"""
|
||||||
site_url = context.get('SITEURL', get_relative_path(filename))
|
self.site_url = context.get('SITEURL', get_relative_path(filename))
|
||||||
|
self.feed_url= '%s/%s' % (self.site_url, filename)
|
||||||
|
|
||||||
feed_class = Rss201rev2Feed if feed_type == 'rss' else Atom1Feed
|
feed = self._create_new_feed(feed_type, context)
|
||||||
|
|
||||||
feed = feed_class(
|
for item in elements:
|
||||||
title=context['SITENAME'],
|
self._add_item_to_the_feed(feed, item)
|
||||||
link=site_url,
|
|
||||||
feed_url= "%s/%s" % (site_url, filename),
|
|
||||||
description=context.get('SITESUBTITLE', ''))
|
|
||||||
for element in elements:
|
|
||||||
feed.add_item(
|
|
||||||
title=element.title,
|
|
||||||
link= "%s/%s" % (site_url, element.url),
|
|
||||||
description=element.content,
|
|
||||||
categories=element.tags if hasattr(element, "tags") else None,
|
|
||||||
author_name=getattr(element, 'author', 'John Doe'),
|
|
||||||
pubdate=element.date)
|
|
||||||
|
|
||||||
if filename:
|
if filename:
|
||||||
complete_path = os.path.join(self.output_path, filename)
|
complete_path = os.path.join(self.output_path, filename)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue