Skip to content
Permalink
Browse files

Merge pull request #2463 from getnikola/rss-for-sections

Rss for sections (#2068)
  • Loading branch information
ralsina committed Aug 21, 2016
2 parents c12a6a1 + 888884e commit 6ff537f5fa8347d1e3a45cf4e4a9f5a993ddc910
Showing with 58 additions and 1 deletion.
  1. +1 −0 CHANGES.txt
  2. +8 −0 docs/path_handlers.txt
  3. +49 −1 nikola/plugins/task/indexes.py
@@ -4,6 +4,7 @@ New in master
Features
--------

* RSS feeds for sections (Issue #2068)
* New ``data`` metadata that loads data from external files (Issue #2450)
* Shortcode to escape to the template language (Issue #1227)
* Added link to raw file in listings (Issue #1995)
@@ -199,6 +199,14 @@ section_index_atom
link://section_index_atom/cars => /cars/index.atom


section_index_rss
Link to the RSS feed for a section.

Example:

link://section_index_atom/cars => /cars/rss.xml


slug
A link to a post with given slug, if not ambiguous.

@@ -36,6 +36,7 @@

from nikola.plugin_categories import Task
from nikola import utils
from nikola.nikola import _enclosure


class Indexes(Task):
@@ -51,6 +52,7 @@ def set_site(self, site):
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 @@ def gen_tasks(self):
"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 @@ def gen_tasks(self):
"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"
@@ -166,6 +173,36 @@ def cat_path(i, displayed_i, num_pages, force_addition, extension=None):
task['basename'] = self.name
yield task

# 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["STORY_INDEX"]:
return
kw = {
@@ -250,7 +287,7 @@ def index_path(self, name, lang, is_feed=False):
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:
@@ -262,6 +299,8 @@ def index_section_path(self, name, lang, is_feed=False):
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]:
@@ -296,3 +335,12 @@ def index_section_atom_path(self, name, lang):
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)

0 comments on commit 6ff537f

Please sign in to comment.
You can’t perform that action at this time.