mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Enables custom locale while feed generation.
Fixes wrong language of month names in feed links. Related to #1198
This commit is contained in:
parent
cb11bea1f2
commit
5ea3a36a3f
1 changed files with 30 additions and 33 deletions
|
|
@ -93,39 +93,36 @@ class Writer(object):
|
||||||
"""
|
"""
|
||||||
if not is_selected_for_writing(self.settings, path):
|
if not is_selected_for_writing(self.settings, path):
|
||||||
return
|
return
|
||||||
old_locale = locale.setlocale(locale.LC_ALL)
|
|
||||||
locale.setlocale(locale.LC_ALL, str('C'))
|
|
||||||
try:
|
|
||||||
self.site_url = context.get(
|
|
||||||
'SITEURL', path_to_url(get_relative_path(path)))
|
|
||||||
|
|
||||||
self.feed_domain = context.get('FEED_DOMAIN')
|
self.site_url = context.get(
|
||||||
self.feed_url = '{}/{}'.format(self.feed_domain, path)
|
'SITEURL', path_to_url(get_relative_path(path)))
|
||||||
|
|
||||||
feed = self._create_new_feed(feed_type, context)
|
self.feed_domain = context.get('FEED_DOMAIN')
|
||||||
|
self.feed_url = '{}/{}'.format(self.feed_domain, path)
|
||||||
|
|
||||||
max_items = len(elements)
|
feed = self._create_new_feed(feed_type, context)
|
||||||
if self.settings['FEED_MAX_ITEMS']:
|
|
||||||
max_items = min(self.settings['FEED_MAX_ITEMS'], max_items)
|
|
||||||
for i in range(max_items):
|
|
||||||
self._add_item_to_the_feed(feed, elements[i])
|
|
||||||
|
|
||||||
if path:
|
max_items = len(elements)
|
||||||
complete_path = os.path.join(self.output_path, path)
|
if self.settings['FEED_MAX_ITEMS']:
|
||||||
try:
|
max_items = min(self.settings['FEED_MAX_ITEMS'], max_items)
|
||||||
os.makedirs(os.path.dirname(complete_path))
|
for i in range(max_items):
|
||||||
except Exception:
|
self._add_item_to_the_feed(feed, elements[i])
|
||||||
pass
|
|
||||||
|
|
||||||
encoding = 'utf-8' if six.PY3 else None
|
if path:
|
||||||
with self._open_w(complete_path, encoding) as fp:
|
complete_path = os.path.join(self.output_path, path)
|
||||||
feed.write(fp, 'utf-8')
|
try:
|
||||||
logger.info('Writing %s', complete_path)
|
os.makedirs(os.path.dirname(complete_path))
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
encoding = 'utf-8' if six.PY3 else None
|
||||||
|
with self._open_w(complete_path, encoding) as fp:
|
||||||
|
feed.write(fp, 'utf-8')
|
||||||
|
logger.info('Writing %s', complete_path)
|
||||||
|
|
||||||
|
signals.feed_written.send(complete_path, context=context, feed=feed)
|
||||||
|
return feed
|
||||||
|
|
||||||
signals.feed_written.send(complete_path, context=context, feed=feed)
|
|
||||||
return feed
|
|
||||||
finally:
|
|
||||||
locale.setlocale(locale.LC_ALL, old_locale)
|
|
||||||
|
|
||||||
def write_file(self, name, template, context, relative_urls=False,
|
def write_file(self, name, template, context, relative_urls=False,
|
||||||
paginated=None, override_output=False, **kwargs):
|
paginated=None, override_output=False, **kwargs):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue