Skip to content
Permalink
Browse files

fixup! Atom syndication and archive support

  • Loading branch information...
da2x committed May 2, 2015
1 parent 1fb7a80 commit 8f3247da13a9effc084ba12b62a27bb7adb6e588
Showing with 55 additions and 64 deletions.
  1. +47 −47 nikola/nikola.py
  2. +6 −15 nikola/plugins/task/indexes.py
  3. +1 −1 nikola/plugins/task/sitemap/__init__.py
  4. +1 −1 nikola/plugins/task/tags.py
@@ -1560,12 +1560,12 @@ def generic_post_list_renderer(self, lang, posts, output_name,
return utils.apply_filters(task, filters)

def atom_feed_renderer(self, lang, posts, output_path, filters,
extra_context):
extra_context):
"""Renders Atom feeds and archives with lists of posts."""
"""Feeds become archives when no longer expected to change"""

def atom_link(link_rel, link_type, link_href):
link=lxml.etree.Element("link")
link = lxml.etree.Element("link")
link.set("rel", link_rel)
link.set("type", link_type)
link.set("href", link_href)
@@ -1594,27 +1594,27 @@ def atom_link(link_rel, link_type, link_href):

deps_context['navigation_links'] = deps_context['global']['navigation_links'](lang)

nslist={}
nslist = {}
if not context["feedpagenum"] == context["feedpagecount"] - 1 and not context["feedpagenum"] == 0:
nslist["fh"]="http://purl.org/syndication/history/1.0"
nslist["fh"] = "http://purl.org/syndication/history/1.0"
if not self.config["RSS_TEASERS"]:
nslist["xh"]="http://www.w3.org/1999/xhtml"
feed_xsl_link=self.abs_link("/assets/xml/atom.xsl")
feed_root=lxml.etree.Element("feed", nsmap=nslist)
nslist["xh"] = "http://www.w3.org/1999/xhtml"
feed_xsl_link = self.abs_link("/assets/xml/atom.xsl")
feed_root = lxml.etree.Element("feed", nsmap=nslist)
feed_root.addprevious(lxml.etree.ProcessingInstruction(
"xml-stylesheet",
'href="' + feed_xsl_link + '" type="text/xsl media="all"'))
feed_root.set("{http://www.w3.org/XML/1998/namespace}lang", lang)
feed_root.set("xmlns", "http://www.w3.org/2005/Atom")
feed_title=lxml.etree.SubElement(feed_root, "title")
feed_title.text=context["title"]
feed_id=lxml.etree.SubElement(feed_root, "id")
feed_id.text=self.abs_link(context["feedlink"])
feed_updated=lxml.etree.SubElement(feed_root, "updated")
feed_updated.text=datetime.datetime.now(tz=dateutil.tz.tzutc()).replace(microsecond=0).isoformat()
feed_author=lxml.etree.SubElement(feed_root, "author")
feed_author_name=lxml.etree.SubElement(feed_author, "name")
feed_author_name.text=self.config["BLOG_AUTHOR"](lang)
feed_title = lxml.etree.SubElement(feed_root, "title")
feed_title.text = context["title"]
feed_id = lxml.etree.SubElement(feed_root, "id")
feed_id.text = self.abs_link(context["feedlink"])
feed_updated = lxml.etree.SubElement(feed_root, "updated")
feed_updated.text = datetime.datetime.now(tz=dateutil.tz.tzutc()).replace(microsecond=0).isoformat()
feed_author = lxml.etree.SubElement(feed_root, "author")
feed_author_name = lxml.etree.SubElement(feed_author, "name")
feed_author_name.text = self.config["BLOG_AUTHOR"](lang)
feed_root.append(atom_link("self", "application/atom+xml",
self.abs_link(context["feedlink"])))
# Older is "next" and newer is "previous" in paginated feeds (opposite of archived)
@@ -1626,7 +1626,7 @@ def atom_link(link_rel, link_type, link_href):
self.abs_link(context["prevfeedlink"])))
if not context["feedpagenum"] == 0:
feed_root.append(atom_link("current", "application/atom+xml",
self.abs_link(context["currentfeedlink"])))
self.abs_link(context["currentfeedlink"])))
# Older is "prev-archive" and newer is "next-archive" in archived feeds (opposite of paginated)
if "prevfeedlink" in context and not context["feedpagenum"] == context["feedpagecount"] - 1:
feed_root.append(atom_link("next-archive", "application/atom+xml",
@@ -1635,12 +1635,12 @@ def atom_link(link_rel, link_type, link_href):
feed_root.append(atom_link("prev-archive", "application/atom+xml",
self.abs_link(context["nextfeedlink"])))
if not context["feedpagenum"] == context["feedpagecount"] - 1:
feed_archive=lxml.etree.SubElement(feed_root, "{http://purl.org/syndication/history/1.0}archive")
lxml.etree.SubElement(feed_root, "{http://purl.org/syndication/history/1.0}archive")
feed_root.append(atom_link("alternate", "text/html",
self.abs_link(context["permalink"])))
feed_generator=lxml.etree.SubElement(feed_root, "generator")
feed_generator.set("uri", "http://getnikola.com/");
feed_generator.text="Nikola"
feed_generator = lxml.etree.SubElement(feed_root, "generator")
feed_generator.set("uri", "http://getnikola.com/")
feed_generator.text = "Nikola"

for post in posts:
data = post.text(lang, teaser_only=self.config["RSS_TEASERS"], strip_html=self.config["RSS_TEASERS"],
@@ -1663,31 +1663,31 @@ def atom_link(link_rel, link_type, link_href):
else: # let other errors raise
raise(e)

entry_root=lxml.etree.SubElement(feed_root, "entry")
entry_title=lxml.etree.SubElement(entry_root, "title")
entry_title.text=post.title(lang)
entry_id=lxml.etree.SubElement(entry_root, "id")
entry_id.text=post.permalink(lang, absolute=True)
entry_updated=lxml.etree.SubElement(entry_root, "updated")
entry_updated.text=post.updated.isoformat()
entry_published=lxml.etree.SubElement(entry_root, "published")
entry_published.text=post.date.isoformat()
entry_author=lxml.etree.SubElement(entry_root, "author")
entry_author_name=lxml.etree.SubElement(entry_author, "name")
entry_author_name.text=post.author(lang)
entry_root = lxml.etree.SubElement(feed_root, "entry")
entry_title = lxml.etree.SubElement(entry_root, "title")
entry_title.text = post.title(lang)
entry_id = lxml.etree.SubElement(entry_root, "id")
entry_id.text = post.permalink(lang, absolute=True)
entry_updated = lxml.etree.SubElement(entry_root, "updated")
entry_updated.text = post.updated.isoformat()
entry_published = lxml.etree.SubElement(entry_root, "published")
entry_published.text = post.date.isoformat()
entry_author = lxml.etree.SubElement(entry_root, "author")
entry_author_name = lxml.etree.SubElement(entry_author, "name")
entry_author_name.text = post.author(lang)
entry_root.append(atom_link("alternate", "text/html",
post.permalink(lang, absolute=True,
query=self.config["RSS_LINKS_APPEND_QUERY"])))
post.permalink(lang, absolute=True,
query=self.config["RSS_LINKS_APPEND_QUERY"])))
if self.config["RSS_TEASERS"]:
entry_summary=lxml.etree.SubElement(entry_root, "summary")
entry_summary.text=data
entry_summary = lxml.etree.SubElement(entry_root, "summary")
entry_summary.text = data
else:
entry_content=lxml.etree.SubElement(entry_root, "content")
entry_content = lxml.etree.SubElement(entry_root, "content")
entry_content.set("type", "xhtml")
entry_content_nsdiv=lxml.etree.SubElement(entry_content, "{http://www.w3.org/1999/xhtml}div")
entry_content_nsdiv.text=data
entry_content_nsdiv = lxml.etree.SubElement(entry_content, "{http://www.w3.org/1999/xhtml}div")
entry_content_nsdiv.text = data
for category in post.tags:
entry_category=lxml.etree.SubElement(entry_root, "category")
entry_category = lxml.etree.SubElement(entry_root, "category")
entry_category.set("term", utils.slugify(category))
entry_category.set("label", category)

@@ -1792,17 +1792,17 @@ def generic_index_renderer(self, lang, posts, indexes_title, template_name, cont
nextlink = i + 1
if prevlink is not None:
context["prevlink"] = page_link(prevlink,
utils.get_displayed_page_number(prevlink, num_pages, self),
num_pages, False)
utils.get_displayed_page_number(prevlink, num_pages, self),
num_pages, False)
context["prevfeedlink"] = page_link(prevlink,
utils.get_displayed_page_number(prevlink, num_pages, self),
utils.get_displayed_page_number(prevlink, num_pages, self),
num_pages, False, extension=".atom")
if nextlink is not None:
context["nextlink"] = page_link(nextlink,
utils.get_displayed_page_number(nextlink, num_pages, self),
num_pages, False)
utils.get_displayed_page_number(nextlink, num_pages, self),
num_pages, False)
context["nextfeedlink"] = page_link(nextlink,
utils.get_displayed_page_number(nextlink, num_pages, self),
utils.get_displayed_page_number(nextlink, num_pages, self),
num_pages, False, extension=".atom")
context["permalink"] = page_link(i, ipages_i, num_pages, False)
output_name = os.path.join(kw['output_folder'], page_path(i, ipages_i, num_pages, False))
@@ -65,12 +65,12 @@ def gen_tasks(self):
def page_link(i, displayed_i, num_pages, force_addition, extension=None):
feed = "_atom" if extension == ".atom" else ""
return utils.adjust_name_for_index_link(self.site.link("index" + feed, None, lang), i, displayed_i,
lang, self.site, force_addition, extension)
lang, self.site, force_addition, extension)

def page_path(i, displayed_i, num_pages, force_addition, extension=None):
feed = "_atom" if extension == ".atom" else ""
return utils.adjust_name_for_index_path(self.site.path("index" + feed, None, lang), i, displayed_i,
lang, self.site, force_addition, extension)
lang, self.site, force_addition, extension)

if kw["show_untranslated_posts"]:
filtered_posts = posts
@@ -133,12 +133,12 @@ def page_path(i, displayed_i, num_pages, force_addition, extension=None):
yield task

def index_path(self, name, lang, is_feed=False):
extension=None
extension = None
if is_feed:
extension=".atom"
index_file=os.path.splitext(self.site.config['INDEX_FILE'])[0] + extension
extension = ".atom"
index_file = os.path.splitext(self.site.config['INDEX_FILE'])[0] + extension
else:
index_file=self.site.config['INDEX_FILE']
index_file = self.site.config['INDEX_FILE']
return utils.adjust_name_for_index_path_list([_f for _f in [self.site.config['TRANSLATIONS'][lang],
self.site.config['INDEX_PATH'],
index_file] if _f],
@@ -150,12 +150,3 @@ def index_path(self, name, lang, is_feed=False):

def index_atom_path(self, name, lang):
return self.index_path(name, lang, is_feed=True)
"""
return utils.adjust_name_for_index_path_list([_f for _f in [self.site.config['TRANSLATIONS'][lang],
self.site.config['INDEX_PATH'],
os.path.splitext(self.site.config['INDEX_FILE'])[0] + ".atom"] if _f],
name,
utils.get_displayed_page_number(name, self.number_of_pages[lang], self.site),
lang,
self.site,
extension=".atom")"""
@@ -177,7 +177,7 @@ def scan_locs():
if path.endswith('.xml') or path.endswith('.atom') or path.endswith('.rss'):
knownroots = (u'<feed', u'<rss', u'<urlset')
filehead = io.open(real_path, 'r', encoding='utf8').read(512)
if any([root in filehead for root in knownroots] ) and path != sitemap_path:
if any([root in filehead for root in knownroots]) and path != sitemap_path:
path = path.replace(os.sep, '/')
lastmod = self.get_lastmod(real_path)
loc = urljoin(base_url, base_path + path)
@@ -231,7 +231,6 @@ def page_link(i, displayed_i, num_pages, force_addition, extension=None):
feed = "_atom" if extension == ".atom" else ""
return utils.adjust_name_for_index_link(self.site.link(kind + feed, tag, lang), i, displayed_i, lang, self.site, force_addition, extension)


def page_path(i, displayed_i, num_pages, force_addition, extension=None):
feed = "_atom" if extension == ".atom" else ""
return utils.adjust_name_for_index_path(self.site.path(kind + feed, tag, lang), i, displayed_i, lang, self.site, force_addition, extension)
@@ -364,6 +363,7 @@ def category_path(self, name, lang):
self.site.config['CATEGORY_PATH'],
self.site.config['CATEGORY_PREFIX'] + self.slugify_name(name) + ".html"] if
_f]

def category_atom_path(self, name, lang):
return [_f for _f in [self.site.config['TRANSLATIONS'][lang],
self.site.config['CATEGORY_PATH'], self.site.config['CATEGORY_PREFIX'] + self.slugify_name(name) + ".atom"] if

0 comments on commit 8f3247d

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