Skip to content
Permalink
Browse files
Add CREATE_ARCHIVE_NAVIGATION (#1639)
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Dec 18, 2016
1 parent c79164b commit e3f1e1564c2ff59c3c721daf1b1430f1ba9d9afd
Showing with 29 additions and 0 deletions.
  1. +2 −0 nikola/conf.py.in
  2. +1 −0 nikola/nikola.py
  3. +26 −0 nikola/plugins/task/archive.py
@@ -432,6 +432,8 @@ FRONT_INDEX_HEADER = {
# CREATE_FULL_ARCHIVES = False
# If monthly archives or full archives are created, adds also one archive per day
# CREATE_DAILY_ARCHIVE = False
# Create previous, up, next navigation links for archives
# CREATE_ARCHIVE_NAVIGATION = False
# Final locations for the archives are:
# output / TRANSLATION[lang] / ARCHIVE_PATH / ARCHIVE_FILENAME
# output / TRANSLATION[lang] / ARCHIVE_PATH / YEAR / index.html
@@ -473,6 +473,7 @@ def __init__(self, **config):
'CONTENT_FOOTER': '',
'CONTENT_FOOTER_FORMATS': {},
'COPY_SOURCES': True,
'CREATE_ARCHIVE_NAVIGATION': False,
'CREATE_MONTHLY_ARCHIVE': False,
'CREATE_SINGLE_ARCHIVE': False,
'CREATE_FULL_ARCHIVES': False,
@@ -27,6 +27,7 @@
"""Classify the posts in archives."""

import os
import natsort
import nikola.utils
import datetime
from nikola.plugin_categories import Taxonomy
@@ -126,6 +127,7 @@ def provide_context_and_uptodate(self, classification, lang, node=None):
hierarchy = self.extract_hierarchy(classification)
kw = {
"messages": self.site.MESSAGES,
"create_archive_navigation": self.site.config["CREATE_ARCHIVE_NAVIGATION"]
}
page_kind = "list"
if self.show_list_as_index:
@@ -150,10 +152,34 @@ def provide_context_and_uptodate(self, classification, lang, node=None):
kw["is_feed_stale"] = (datetime.datetime.utcnow().strftime("%Y/%m/%d") != classification)
else:
raise Exception("Cannot interpret classification {}!".format(repr(classification)))

context = {
"title": title,
"pagekind": [page_kind, "archive_page"],
}

# Generate links for hierarchies
if kw["create_archive_navigation"]:
if hierarchy:
# Up level link makes sense only if this is not the top-level
# page (hierarchy is empty)
context["up_level"] = self.site.link('/'.join(hierarchy[:-1]), lang)
else:
context["up_level"] = None

flat_hierarchy = self.site.flat_hierarchy_per_classification['archive'][lang]
nodelevel = len(hierarchy)
flat_samelevel = [node.classification_name for node in flat_hierarchy if len(node.classification_path) == nodelevel]
# We need to sort it. Natsort means it’s year 10000 compatible!
flat_samelevel = natsort.natsorted(flat_samelevel, alg=natsort.ns.F | natsort.ns.IC)
idx = flat_samelevel.find(classification)
if idx == -1:
raise Exception("Cannot find classification {0} in flat hierarchy!".format(classification))
previdx, nextidx = idx - 1, idx + 1
# If the previous index is -1, or the next index is 1, the previous/next archive does not exist.
context["previous_archive"] = self.site.link(flat_samelevel[previdx], lang) if previdx != -1 else None
context["next_archive"] = self.site.link(flat_samelevel[nextidx], lang) if nextidx != -1 else None

if page_kind == 'index':
context["archive_name"] = classification if classification else None
context["is_feed_stale"] = kw["is_feed_stale"]

0 comments on commit e3f1e15

Please sign in to comment.