aboutsummaryrefslogtreecommitdiffstats
path: root/nikola/plugins/task_archive.py
diff options
context:
space:
mode:
authorLibravatarAgustin Henze <tin@sluc.org.ar>2013-05-30 17:41:06 -0300
committerLibravatarAgustin Henze <tin@sluc.org.ar>2013-05-30 17:41:06 -0300
commit0c4dfdec5b55b6064dccc38bbfb0a7c0699c895a (patch)
treea6707225ccc559f7edf50ddd3fdc7fc85145c921 /nikola/plugins/task_archive.py
parent8b14a1e5b2ca574fdd4fd2377567ec98a110d4b6 (diff)
Imported Upstream version 5.4.4
Diffstat (limited to 'nikola/plugins/task_archive.py')
-rw-r--r--nikola/plugins/task_archive.py66
1 files changed, 57 insertions, 9 deletions
diff --git a/nikola/plugins/task_archive.py b/nikola/plugins/task_archive.py
index f91a10e..a67826f 100644
--- a/nikola/plugins/task_archive.py
+++ b/nikola/plugins/task_archive.py
@@ -22,7 +22,9 @@
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+import calendar
import os
+import sys
from nikola.plugin_categories import Task
from nikola.utils import config_changed
@@ -39,16 +41,51 @@ class Archive(Task):
"translations": self.site.config['TRANSLATIONS'],
"output_folder": self.site.config['OUTPUT_FOLDER'],
"filters": self.site.config['FILTERS'],
+ "create_monthly_archive": self.site.config['CREATE_MONTHLY_ARCHIVE'],
}
self.site.scan_posts()
# TODO add next/prev links for years
- template_name = "list_post.tmpl"
- # TODO: posts_per_year is global, kill it
- for year, posts in list(self.site.posts_per_year.items()):
- for lang in kw["translations"]:
+ for lang in kw["translations"]:
+ for year, posts in self.site.posts_per_year.items():
+ output_name = os.path.join(
+ kw['output_folder'], self.site.path("archive", year, lang))
+ context = {}
+ context["lang"] = lang
+ context["title"] = kw["messages"][lang]["Posts for year %s"] % year
+ context["permalink"] = self.site.link("archive", year, lang)
+ if not kw["create_monthly_archive"]:
+ template_name = "list_post.tmpl"
+ post_list = [self.site.global_data[post] for post in posts]
+ post_list.sort(key=lambda a: a.date)
+ post_list.reverse()
+ context["posts"] = post_list
+ else: # Monthly archives, just list the months
+ months = set([m.split('/')[1] for m in self.site.posts_per_month.keys() if m.startswith(str(year))])
+ months = sorted(list(months))
+ template_name = "list.tmpl"
+ context["items"] = [[get_month_name(int(month), lang), month] for month in months]
+ post_list = []
+ task = self.site.generic_post_list_renderer(
+ lang,
+ [],
+ output_name,
+ template_name,
+ kw['filters'],
+ context,
+ )
+ task_cfg = {1: task['uptodate'][0].config, 2: kw}
+ task['uptodate'] = [config_changed(task_cfg)]
+ task['basename'] = self.name
+ yield task
+
+ if not kw["create_monthly_archive"]:
+ continue # Just to avoid nesting the other loop in this if
+ template_name = "list_post.tmpl"
+ for yearmonth, posts in self.site.posts_per_month.items():
output_name = os.path.join(
- kw['output_folder'], self.site.path("archive", year,
- lang)).encode('utf8')
+ kw['output_folder'], self.site.path("archive", yearmonth,
+ lang))
+ year, month = yearmonth.split('/')
post_list = [self.site.global_data[post] for post in posts]
post_list.sort(key=lambda a: a.date)
post_list.reverse()
@@ -56,8 +93,9 @@ class Archive(Task):
context["lang"] = lang
context["posts"] = post_list
context["permalink"] = self.site.link("archive", year, lang)
- context["title"] = kw["messages"][lang]["Posts for year %s"]\
- % year
+
+ context["title"] = kw["messages"][lang]["Posts for {month} {year}"].format(
+ year=year, month=get_month_name(int(month), lang))
task = self.site.generic_post_list_renderer(
lang,
post_list,
@@ -80,7 +118,7 @@ class Archive(Task):
context = {}
output_name = os.path.join(
kw['output_folder'], self.site.path("archive", None,
- lang)).encode('utf8')
+ lang))
context["title"] = kw["messages"][lang]["Archive"]
context["items"] = [(year, self.site.link("archive", year, lang))
for year in years]
@@ -97,3 +135,13 @@ class Archive(Task):
task['uptodate'] = [config_changed(task_cfg)]
task['basename'] = self.name
yield task
+
+
+def get_month_name(month_no, locale):
+ if sys.version_info[0] == 3: # Python 3
+ with calendar.different_locale((locale, "UTF-8")):
+ s = calendar.month_name[month_no]
+ else: # Python 2
+ with calendar.TimeEncoding((locale, "UTF-8")):
+ s = calendar.month_name[month_no]
+ return s