Skip to content
Permalink
Browse files
pagekind for theming
  • Loading branch information
da2x committed Jul 12, 2015
1 parent 001bc22 commit ac9a7bc7c2dc941ff993ed119d94851762c96586
@@ -4,6 +4,7 @@ New in master
Features
--------

* New ‘pagekind’ variable available to identify different kind of pages from theme templates
* Add ``--no-server`` option to ``nikola auto`` (Issue #1883)
* Always return unicode in slugify (Issue #1885)
* Remove logging handlers (Issue #1797)
@@ -1524,9 +1524,9 @@ def scan_posts(self, really=False, ignore_quit=False, quiet=False):
sys.exit(1)
signal('scanned').send(self)

def generic_page_renderer(self, lang, post, filters):
def generic_page_renderer(self, lang, post, filters, context=None):
"""Render post fragments to final HTML pages."""
context = {}
context = context.copy() if context else {}
deps = post.deps(lang) + \
self.template_system.template_deps(post.template_name)
deps.extend(utils.get_asset_path(x, self.THEMES) for x in ('bundles', 'parent', 'engine'))
@@ -1536,6 +1536,8 @@ def generic_page_renderer(self, lang, post, filters):
context['title'] = post.title(lang)
context['description'] = post.description(lang)
context['permalink'] = post.permalink(lang)
if not 'pagekind' in context:
context['pagekind'] = ['generic_page']
if post.use_in_feeds:
context['enable_comments'] = True
else:
@@ -1823,6 +1825,8 @@ def generic_index_renderer(self, lang, posts, indexes_title, template_name, cont
num_pages = len(lists)
for i, post_list in enumerate(lists):
context = context_source.copy()
if not 'pagekind' in context:
context['pagekind'] = ['index']
ipages_i = utils.get_displayed_page_number(i, num_pages, self)
if kw["indexes_pages"]:
indexes_pages = kw["indexes_pages"] % ipages_i
@@ -58,6 +58,7 @@ def _prepare_task(self, kw, name, lang, posts, items, template_name,
context["lang"] = lang
context["title"] = title
context["permalink"] = self.site.link("archive", name, lang)
context["pagekind"] = ["list", "archive_page"]
if posts is not None:
context["posts"] = posts
n = len(posts)
@@ -97,13 +98,15 @@ def page_path(i, displayed_i, num_pages, force_addition, extension=None):
uptodate = []
if deps_translatable is not None:
uptodate += [config_changed(deps_translatable, 'nikola.plugins.task.archive')]
context = {"archive_name": name,
"is_feed_stale": kw["is_feed_stale"],
"pagekind": ["index", "archive_page"]}
yield self.site.generic_index_renderer(
lang,
posts,
title,
"archiveindex.tmpl",
{"archive_name": name,
"is_feed_stale": kw["is_feed_stale"]},
context,
kw,
str(self.name),
page_link,
@@ -240,6 +240,7 @@ def gen_tasks(self):
context["permalink"] = self.site.link("gallery", gallery, lang)
context["enable_comments"] = self.kw['comments_in_galleries']
context["thumbnail_size"] = self.kw["thumbnail_size"]
context["pagekind"] = ["gallery_front"]

if post:
yield {
@@ -261,6 +262,8 @@ def gen_tasks(self):
file_dep += [post.translated_base_path(l) for l in self.kw['translations']]
file_dep_dest += [post.translated_base_path(l) for l in self.kw['translations']]

context["pagekind"] = ["gallery_page"]

yield utils.apply_filters({
'basename': self.name,
'name': dst,
@@ -80,7 +80,10 @@ def page_path(i, displayed_i, num_pages, force_addition, extension=None):
indexes_title = kw['indexes_title'](lang) or kw['blog_title'](lang)
self.number_of_pages[lang] = (len(filtered_posts) + kw['index_display_post_count'] - 1) // kw['index_display_post_count']

yield self.site.generic_index_renderer(lang, filtered_posts, indexes_title, template_name, {}, kw, 'render_indexes', page_link, page_path)
context = {}
context["pagekind"] = ["index"]

yield self.site.generic_index_renderer(lang, filtered_posts, indexes_title, template_name, context, kw, 'render_indexes', page_link, page_path)

if not self.site.config["STORY_INDEX"]:
return
@@ -112,6 +115,9 @@ def page_path(i, displayed_i, num_pages, force_addition, extension=None):
if kw['strip_indexes'] and link[-(1 + index_len):] == '/' + kw['index_file']:
link = link[:-index_len]
context["permalink"] = link
context["pagekind"] = ["list"]
if dirnme == "/":
context["pagekind"].append("front_page")

for post in post_list:
# If there is an index.html pending to be created from
@@ -149,6 +149,7 @@ def render_listing(in_name, out_name, input_folder, output_folder, folders=[], f
files, alg=natsort.ns.F | natsort.ns.IC),
'description': title,
'source_link': source_link,
'pagekind': ['listing'],
}
self.site.render_template('listing.tmpl', out_name, context)

@@ -49,8 +49,11 @@ def gen_tasks(self):
for post in self.site.timeline:
if not kw["show_untranslated_posts"] and not post.is_translation_available(lang):
continue
for task in self.site.generic_page_renderer(lang, post,
kw["filters"]):
if post.is_post:
context = {'pagekind': ['post_page',]}
else:
context = {'pagekind': ['pages_page',]}
for task in self.site.generic_page_renderer(lang, post, kw["filters"], context):
task['uptodate'] = task['uptodate'] + [config_changed(kw, 'nikola.plugins.task.pages')]
task['basename'] = self.name
task['task_dep'] = ['render_posts']
@@ -219,6 +219,7 @@ def _create_tags_page(self, kw, include_tags=True, include_categories=True):
context["cat_items"] = None
context["permalink"] = self.site.link("tag_index" if has_tags else "category_index", None, lang)
context["description"] = context["title"]
context["pagekind"] = ["list", "tags_page"]
task = self.site.generic_post_list_renderer(
lang,
[],
@@ -284,6 +285,7 @@ def page_path(i, displayed_i, num_pages, force_addition, extension=None):
context_source["description"] = self._get_description(tag, is_category, lang)
if is_category:
context_source["subcategories"] = self._get_subcategories(tag)
context_source["pagekind"] = ["index", "tag_page"]
template_name = "tagindex.tmpl"

yield self.site.generic_index_renderer(lang, post_list, indexes_title, template_name, context_source, kw, str(self.name), page_link, page_path)
@@ -308,6 +310,7 @@ def tag_page_as_list(self, tag, lang, post_list, kw, is_category):
context["description"] = self._get_description(tag, is_category, lang)
if is_category:
context["subcategories"] = self._get_subcategories(tag)
context_source["pagekind"] = ["list", "tag_page"]
task = self.site.generic_post_list_renderer(
lang,
post_list,

0 comments on commit ac9a7bc

Please sign in to comment.