Skip to content
Browse files
jsonfeed: Archive support; titles and descriptions
Signed-off-by: Chris Warrick <>
  • Loading branch information
Kwpolska committed May 21, 2017
1 parent 315c886 commit 1f29bb55a5756ae872c066e4f6dcc225d576196e
Showing 1 changed file with 33 additions and 8 deletions.
@@ -46,6 +46,7 @@ class JSONFeed(Task):

name = "jsonfeed"
supported_taxonomies = {
'archive': 'archive_jsonfeed',
'author': 'author_jsonfeed',
'category': 'category_jsonfeed',
'section_index': 'section_index_jsonfeed',
@@ -68,6 +69,10 @@ def set_site(self, site):
}"index_jsonfeed", self.index_jsonfeed_path)
@@ -79,52 +84,68 @@ def gen_tasks(self):
yield self.group_task()

# Main feed
for lang in
# Main feed
title =['blog_title'](lang)
link =['site_url']
description =['blog_description'](lang)
timeline =[['feed_length']]
output_name = os.path.normpath(os.path.join(['OUTPUT_FOLDER'],"index_jsonfeed", "", lang)))
feed_url = urljoin(['BASE_URL'],"index_jsonfeed", "", lang).lstrip('/'))
feed_url = self.get_link("index_jsonfeed", "", lang)

yield self.generate_feed_task(lang, title, link, description,
timeline, feed_url, output_name)

for classification_name, path_handler in self.supported_taxonomies.items():
taxonomy =[classification_name]

if classification_name == "archive" and not['archives_are_indexes']:

classification_timelines = {}
for tlang, posts_per_classification in[taxonomy.classification_name].items():
if lang != tlang and not taxonomy.also_create_classifications_from_other_languages:

for classification, timeline in classification_timelines.items():
# TODO better values for ↓↓↓
title =['blog_title'](lang) # Debatable: could also be classification name etc
link =['site_url'] # Debatable: spec unclear
description =['blog_description'](lang) # Debatable: do classifications have descriptions?
if not classification:
if taxonomy.has_hierarchy:
node =[taxonomy.classification_name][lang][classification]
taxo_context = taxonomy.provide_context_and_uptodate(classification, lang, node)[0]
taxo_context = taxonomy.provide_context_and_uptodate(classification, lang)[0]
title = taxo_context.get('title', classification)
link = self.get_link(classification_name, classification, lang)
description = taxo_context.get('description',['blog_description'](lang))
timeline = timeline[['feed_length']]
output_name = os.path.normpath(os.path.join(['OUTPUT_FOLDER'],, classification, lang)))
feed_url = urljoin(['BASE_URL'],, classification, lang).lstrip('/'))
feed_url = self.get_link(path_handler, classification, lang)

# Special handling for author pages
if classification_name == "author":
primary_author = {
'name': classification,
'url': urljoin(['BASE_URL'],"author_index", classification, lang).lstrip('/'))
'url': link
primary_author = None

yield self.generate_feed_task(lang, title, link, description,
timeline, feed_url, output_name, primary_author)

def index_jsonfeed_path(self, name, lang, **kwargs):
"""Return path to main JSON Feed."""
return [_f for _f in [['TRANSLATIONS'][lang], 'feed.json'] if _f]

def archive_jsonfeed_path(self, name, lang, **kwargs):
"""Return path to archive JSON Feed."""
return [_f for _f in [['TRANSLATIONS'][lang],['ARCHIVE_PATH'], name, 'feed.json'] if _f]

def author_jsonfeed_path(self, name, lang, **kwargs):
"""Return path to author JSON Feed."""
@@ -153,6 +174,10 @@ def tag_jsonfeed_path(self, name, lang, **kwargs):
return [_f for _f in [['TRANSLATIONS'][lang],['TAG_PATH'](lang), name + '-feed.json'] if _f]

def get_link(self, path_handler, classification, lang):
"""Get link for a page."""
return urljoin(['BASE_URL'],, classification, lang).lstrip('/'))

def generate_feed_task(self, lang, title, link, description, timeline,
feed_url, output_name, primary_author=None):
"""Generate a task to create a feed."""

0 comments on commit 1f29bb5

Please sign in to comment.