Added support for category and lang for period generator

This commit is contained in:
Fernando Flórez 2014-04-15 13:24:24 -05:00
commit 226b5db6bb

View file

@ -309,6 +309,8 @@ class ArticlesGenerator(Generator):
# format string syntax can be used for specifying the
# period archive dates
date = archive[0].date
category = archive[0].category
lang = archive[0].lang
# Under python 2, with non-ascii locales, u"{:%b}".format(date) might raise UnicodeDecodeError
# because u"{:%b}".format(date) will call date.__format__(u"%b"), which will return a byte string
# and not a unicode string.
@ -316,12 +318,20 @@ class ArticlesGenerator(Generator):
# locale.setlocale(locale.LC_ALL, 'ja_JP.utf8')
# date.__format__(u"%b") == '12\xe6\x9c\x88' # True
try:
save_as = save_as_fmt.format(date=date)
save_as = save_as_fmt.format(
date=date,
category=category,
lang=lang
)
except UnicodeDecodeError:
# Python2 only:
# Let date.__format__() work with byte strings instead of characters since it fails to work with characters
bytes_save_as_fmt = save_as_fmt.encode('utf8')
bytes_save_as = bytes_save_as_fmt.format(date=date)
bytes_save_as = bytes_save_as_fmt.format(
date=date,
category=category,
lang=lang
)
save_as = unicode(bytes_save_as,'utf8')
context = self.context.copy()