aboutsummaryrefslogtreecommitdiffstats
path: root/nikola/plugins/task/indexes.py
diff options
context:
space:
mode:
authorLibravatarDererk <dererk@satellogic.com>2016-11-15 14:18:46 -0300
committerLibravatarDererk <dererk@satellogic.com>2016-11-15 14:18:46 -0300
commitffb671c61a24a9086343b54bad080e145ff33fc5 (patch)
tree2c5291f7a34edf4afdc8e07887a148291bfa3fa1 /nikola/plugins/task/indexes.py
parent4e3224c012df9f74f010eb92203520515e8537b9 (diff)
New upstream version 7.8.1upstream/7.8.1
Diffstat (limited to 'nikola/plugins/task/indexes.py')
-rw-r--r--nikola/plugins/task/indexes.py72
1 files changed, 59 insertions, 13 deletions
diff --git a/nikola/plugins/task/indexes.py b/nikola/plugins/task/indexes.py
index 2ab97fa..8ecd1de 100644
--- a/nikola/plugins/task/indexes.py
+++ b/nikola/plugins/task/indexes.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
-# Copyright © 2012-2015 Roberto Alsina and others.
+# Copyright © 2012-2016 Roberto Alsina and others.
# Permission is hereby granted, free of charge, to any
# person obtaining a copy of this software and associated
@@ -36,6 +36,7 @@ except ImportError:
from nikola.plugin_categories import Task
from nikola import utils
+from nikola.nikola import _enclosure
class Indexes(Task):
@@ -51,6 +52,7 @@ class Indexes(Task):
site.register_path_handler('index_atom', self.index_atom_path)
site.register_path_handler('section_index', self.index_section_path)
site.register_path_handler('section_index_atom', self.index_section_atom_path)
+ site.register_path_handler('section_index_rss', self.index_section_rss_path)
return super(Indexes, self).set_site(site)
def _get_filtered_posts(self, lang, show_untranslated_posts):
@@ -77,6 +79,10 @@ class Indexes(Task):
"translations": self.site.config['TRANSLATIONS'],
"messages": self.site.MESSAGES,
"output_folder": self.site.config['OUTPUT_FOLDER'],
+ "feed_length": self.site.config['FEED_LENGTH'],
+ "feed_links_append_query": self.site.config["FEED_LINKS_APPEND_QUERY"],
+ "feed_teasers": self.site.config["FEED_TEASERS"],
+ "feed_plain": self.site.config["FEED_PLAIN"],
"filters": self.site.config['FILTERS'],
"index_file": self.site.config['INDEX_FILE'],
"show_untranslated_posts": self.site.config['SHOW_UNTRANSLATED_POSTS'],
@@ -85,6 +91,7 @@ class Indexes(Task):
"strip_indexes": self.site.config['STRIP_INDEXES'],
"blog_title": self.site.config["BLOG_TITLE"],
"generate_atom": self.site.config["GENERATE_ATOM"],
+ "site_url": self.site.config["SITE_URL"],
}
template_name = "index.tmpl"
@@ -110,8 +117,6 @@ class Indexes(Task):
yield self.site.generic_index_renderer(lang, filtered_posts, indexes_title, template_name, context, kw, 'render_indexes', page_link, page_path)
if self.site.config['POSTS_SECTIONS']:
-
- kw["posts_section_are_indexes"] = self.site.config['POSTS_SECTION_ARE_INDEXES']
index_len = len(kw['index_file'])
groups = defaultdict(list)
@@ -145,16 +150,16 @@ class Indexes(Task):
context["pagekind"] = ["section_page"]
context["description"] = self.site.config['POSTS_SECTION_DESCRIPTIONS'](lang)[section_slug] if section_slug in self.site.config['POSTS_SECTION_DESCRIPTIONS'](lang) else ""
- if kw["posts_section_are_indexes"]:
+ if self.site.config["POSTS_SECTION_ARE_INDEXES"]:
context["pagekind"].append("index")
- kw["posts_section_title"] = self.site.config['POSTS_SECTION_TITLE'](lang)
+ posts_section_title = self.site.config['POSTS_SECTION_TITLE'](lang)
section_title = None
- if type(kw["posts_section_title"]) is dict:
- if section_slug in kw["posts_section_title"]:
- section_title = kw["posts_section_title"][section_slug]
- elif type(kw["posts_section_title"]) is str:
- section_title = kw["posts_section_title"]
+ if type(posts_section_title) is dict:
+ if section_slug in posts_section_title:
+ section_title = posts_section_title[section_slug]
+ elif type(posts_section_title) is str:
+ section_title = posts_section_title
if not section_title:
section_title = post_list[0].section_name(lang)
section_title = section_title.format(name=post_list[0].section_name(lang))
@@ -168,7 +173,37 @@ class Indexes(Task):
task['basename'] = self.name
yield task
- if not self.site.config["STORY_INDEX"]:
+ # RSS feed for section
+ deps = []
+ deps_uptodate = []
+ if kw["show_untranslated_posts"]:
+ posts = post_list[:kw['feed_length']]
+ else:
+ posts = [x for x in post_list if x.is_translation_available(lang)][:kw['feed_length']]
+ for post in posts:
+ deps += post.deps(lang)
+ deps_uptodate += post.deps_uptodate(lang)
+
+ feed_url = urljoin(self.site.config['BASE_URL'], self.site.link('section_index_rss', section_slug, lang).lstrip('/'))
+ output_name = os.path.join(kw['output_folder'], self.site.path('section_index_rss', section_slug, lang).lstrip(os.sep))
+ task = {
+ 'basename': self.name,
+ 'name': os.path.normpath(output_name),
+ 'file_dep': deps,
+ 'targets': [output_name],
+ 'actions': [(utils.generic_rss_renderer,
+ (lang, kw["blog_title"](lang), kw["site_url"],
+ context["description"], posts, output_name,
+ kw["feed_teasers"], kw["feed_plain"], kw['feed_length'], feed_url,
+ _enclosure, kw["feed_links_append_query"]))],
+
+ 'task_dep': ['render_posts'],
+ 'clean': True,
+ 'uptodate': [utils.config_changed(kw, 'nikola.plugins.indexes')] + deps_uptodate,
+ }
+ yield task
+
+ if not self.site.config["PAGE_INDEX"]:
return
kw = {
"translations": self.site.config['TRANSLATIONS'],
@@ -207,7 +242,7 @@ class Indexes(Task):
for post in post_list:
# If there is an index.html pending to be created from
- # a story, do not generate the STORY_INDEX
+ # a page, do not generate the PAGE_INDEX
if post.destination_path(lang) == short_destination:
should_render = False
else:
@@ -252,7 +287,7 @@ class Indexes(Task):
self.site,
extension=extension)
- def index_section_path(self, name, lang, is_feed=False):
+ def index_section_path(self, name, lang, is_feed=False, is_rss=False):
"""Link to the index for a section.
Example:
@@ -264,6 +299,8 @@ class Indexes(Task):
if is_feed:
extension = ".atom"
index_file = os.path.splitext(self.site.config['INDEX_FILE'])[0] + extension
+ elif is_rss:
+ index_file = 'rss.xml'
else:
index_file = self.site.config['INDEX_FILE']
if name in self.number_of_pages_section[lang]:
@@ -298,3 +335,12 @@ class Indexes(Task):
link://section_index_atom/cars => /cars/index.atom
"""
return self.index_section_path(name, lang, is_feed=True)
+
+ def index_section_rss_path(self, name, lang):
+ """Link to the RSS feed for a section.
+
+ Example:
+
+ link://section_index_rss/cars => /cars/rss.xml
+ """
+ return self.index_section_path(name, lang, is_rss=True)