mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Set locale to default while writing RSS feeds
to always output RFC822 compatible dates. Fixes #67
This commit is contained in:
parent
06246d1aa4
commit
bbd8305310
2 changed files with 30 additions and 21 deletions
|
|
@ -3,9 +3,9 @@ import os
|
||||||
import re
|
import re
|
||||||
from codecs import open
|
from codecs import open
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
import locale
|
||||||
|
|
||||||
from feedgenerator import Atom1Feed, Rss201rev2Feed
|
from feedgenerator import Atom1Feed, Rss201rev2Feed
|
||||||
|
|
||||||
from pelican.utils import get_relative_path
|
from pelican.utils import get_relative_path
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -26,6 +26,7 @@ class Writer(object):
|
||||||
|
|
||||||
|
|
||||||
def _add_item_to_the_feed(self, feed, item):
|
def _add_item_to_the_feed(self, feed, item):
|
||||||
|
|
||||||
feed.add_item(
|
feed.add_item(
|
||||||
title=item.title,
|
title=item.title,
|
||||||
link='%s/%s' % (self.site_url, item.url),
|
link='%s/%s' % (self.site_url, item.url),
|
||||||
|
|
@ -46,26 +47,31 @@ 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)
|
||||||
"""
|
"""
|
||||||
self.site_url = context.get('SITEURL', get_relative_path(filename))
|
old_locale = locale.getlocale(locale.LC_ALL)
|
||||||
self.feed_url= '%s/%s' % (self.site_url, filename)
|
locale.setlocale(locale.LC_ALL, 'C')
|
||||||
|
try:
|
||||||
|
self.site_url = context.get('SITEURL', get_relative_path(filename))
|
||||||
|
self.feed_url= '%s/%s' % (self.site_url, filename)
|
||||||
|
|
||||||
feed = self._create_new_feed(feed_type, context)
|
feed = self._create_new_feed(feed_type, context)
|
||||||
|
|
||||||
for item in elements:
|
for item in elements:
|
||||||
self._add_item_to_the_feed(feed, item)
|
self._add_item_to_the_feed(feed, item)
|
||||||
|
|
||||||
if filename:
|
if filename:
|
||||||
complete_path = os.path.join(self.output_path, filename)
|
complete_path = os.path.join(self.output_path, filename)
|
||||||
try:
|
try:
|
||||||
os.makedirs(os.path.dirname(complete_path))
|
os.makedirs(os.path.dirname(complete_path))
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
fp = open(complete_path, 'w')
|
fp = open(complete_path, 'w')
|
||||||
feed.write(fp, 'utf-8')
|
feed.write(fp, 'utf-8')
|
||||||
print u' [ok] writing %s' % complete_path
|
print u' [ok] writing %s' % complete_path
|
||||||
|
|
||||||
fp.close()
|
fp.close()
|
||||||
return feed
|
return feed
|
||||||
|
finally:
|
||||||
|
locale.setlocale(locale.LC_ALL, old_locale)
|
||||||
|
|
||||||
def write_file(self, name, template, context, relative_urls=True,
|
def write_file(self, name, template, context, relative_urls=True,
|
||||||
**kwargs):
|
**kwargs):
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,9 @@ PDF_GENERATOR = False
|
||||||
REVERSE_CATEGORY_ORDER = True
|
REVERSE_CATEGORY_ORDER = True
|
||||||
LOCALE = 'fr_FR.utf8'
|
LOCALE = 'fr_FR.utf8'
|
||||||
|
|
||||||
|
FEED_RSS = 'feeds/all.rss.xml'
|
||||||
|
CATEGORY_FEED_RSS = 'feeds/%s.rss.xml'
|
||||||
|
|
||||||
LINKS = (('Biologeek', 'http://biologeek.org'),
|
LINKS = (('Biologeek', 'http://biologeek.org'),
|
||||||
('Filyb', "http://filyb.info/"),
|
('Filyb', "http://filyb.info/"),
|
||||||
('Libert-fr', "http://www.libert-fr.com"),
|
('Libert-fr', "http://www.libert-fr.com"),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue