Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
RSS_LINKS_APPEND_QUERY enhancements and fixes
Substitutions for RSS_LINKS_APPEND_QUERY for identifying the source
feed address (feedRelUri) and the kind of feed (feedFormat).
  • Loading branch information
da2x committed May 3, 2015
1 parent 0def2e0 commit 62e9459
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt
Expand Up @@ -4,6 +4,8 @@ New in master
Features
--------

* Substitutions for RSS_LINKS_APPEND_QUERY for identifying
the source feed (feedRelUri) and the kind of feed (feedFormat).
* New option GENERATE_ATOM, off by default
* Current and archive Atom feeds for indexes and category/tag indexes (RFC-4287 and RFC-5005)
* Atom feed auto-discovery in HTML indexes and category/tag indexes
Expand All @@ -24,6 +26,7 @@ Features
Bugfixes
--------

* RSS_LINKS_APPEND_QUERY not working in RSS feeds for tags
* Don’t use sets for ``FAVICONS`` (Issue #1674)
* Posts/Pages that use post-list will never be up to date (Issue #1671)
* Support using post.text() in post_list_directive.tmpl (Issue #1671)
Expand Down
10 changes: 7 additions & 3 deletions nikola/conf.py.in
Expand Up @@ -557,9 +557,13 @@ INDEX_READ_MORE_LINK = ${INDEX_READ_MORE_LINK}
RSS_READ_MORE_LINK = ${RSS_READ_MORE_LINK}

# Append a URL query to the RSS_READ_MORE_LINK in Atom and RSS feeds. Advanced
# option used for traffic source tracking. Minimum example for use with Piwik:
# "pk_campaign=rss" and for use with Google Analytics
# "utm_source=feed&utm_medium=feed&utm_campaign=feed".
# option used for traffic source tracking.
# Minimum example for use with Piwik: "pk_campaign=feed"
# The following tags exist and are replaced for you:
# {feedRelUri} A relative link to the feed.
# {feedFormat} The name of the syndication format.
# Example using replacement for use with Google Analytics:
# "utm_source={feedRelUri}&utm_medium=nikola_feed&utm_campaign={feedFormat}_feed"
RSS_LINKS_APPEND_QUERY = False

# A HTML fragment describing the license, for the sidebar.
Expand Down
20 changes: 16 additions & 4 deletions nikola/nikola.py
Expand Up @@ -1101,9 +1101,15 @@ def generic_rss_renderer(self, lang, title, link, description, timeline, output_

items = []

feed_append_query = None
if rss_links_append_query:
feed_append_query = rss_links_append_query.format(
feedRelUri='/' + feed_url[len(self.config['BASE_URL']):],
feedFormat="rss")

for post in timeline[:feed_length]:
data = post.text(lang, teaser_only=rss_teasers, strip_html=rss_plain,
rss_read_more_link=True, rss_links_append_query=rss_links_append_query)
rss_read_more_link=True, rss_links_append_query=feed_append_query)
if feed_url is not None and data:
# Massage the post's HTML (unless plain)
if not rss_plain:
Expand All @@ -1125,7 +1131,7 @@ def generic_rss_renderer(self, lang, title, link, description, timeline, output_
raise(e)
args = {
'title': post.title(lang),
'link': post.permalink(lang, absolute=True, query=rss_links_append_query),
'link': post.permalink(lang, absolute=True, query=feed_append_query),
'description': data,
# PyRSS2Gen's pubDate is GMT time.
'pubDate': (post.date if post.date.tzinfo is None else
Expand Down Expand Up @@ -1642,9 +1648,15 @@ def atom_link(link_rel, link_type, link_href):
feed_generator.set("uri", "http://getnikola.com/")
feed_generator.text = "Nikola"

feed_append_query = None
if self.config["RSS_LINKS_APPEND_QUERY"]:
feed_append_query = self.config["RSS_LINKS_APPEND_QUERY"].format(
feedRelUri=context["feedlink"],
feedFormat="atom")

for post in posts:
data = post.text(lang, teaser_only=self.config["RSS_TEASERS"], strip_html=self.config["RSS_TEASERS"],
rss_read_more_link=True, rss_links_append_query=self.config["RSS_LINKS_APPEND_QUERY"])
rss_read_more_link=True, rss_links_append_query=feed_append_query)
if not self.config["RSS_TEASERS"]:
# FIXME: this is duplicated with code in Post.text() and generic_rss_renderer
try:
Expand Down Expand Up @@ -1677,7 +1689,7 @@ def atom_link(link_rel, link_type, link_href):
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"])))
query=feed_append_query)))
if self.config["RSS_TEASERS"]:
entry_summary = lxml.etree.SubElement(entry_root, "summary")
entry_summary.text = data
Expand Down
3 changes: 2 additions & 1 deletion nikola/plugins/task/tags.py
Expand Up @@ -74,6 +74,7 @@ def gen_tasks(self):
"generate_rss": self.site.config['GENERATE_RSS'],
"rss_teasers": self.site.config["RSS_TEASERS"],
"rss_plain": self.site.config["RSS_PLAIN"],
"rss_link_append_query": self.site.config["RSS_LINKS_APPEND_QUERY"],
"show_untranslated_posts": self.site.config['SHOW_UNTRANSLATED_POSTS'],
"feed_length": self.site.config['FEED_LENGTH'],
"taglist_minimum_post_count": self.site.config['TAGLIST_MINIMUM_POSTS'],
Expand Down Expand Up @@ -307,7 +308,7 @@ def tag_rss(self, tag, lang, posts, kw, is_category):
(lang, "{0} ({1})".format(kw["blog_title"](lang), tag),
kw["site_url"], None, post_list,
output_name, kw["rss_teasers"], kw["rss_plain"], kw['feed_length'],
feed_url))],
feed_url, None, kw["rss_link_append_query"]))],
'clean': True,
'uptodate': [utils.config_changed(kw, 'nikola.plugins.task.tags:rss')] + deps_uptodate,
'task_dep': ['render_posts'],
Expand Down

0 comments on commit 62e9459

Please sign in to comment.