Merge branch 'pr/551' (closes #551)

This commit is contained in:
Bruno Binet 2012-11-12 23:57:37 +01:00
commit f49336f087
13 changed files with 93 additions and 35 deletions

View file

@ -11,6 +11,9 @@ Release history
* Improved appearance of LinkedIn icon in default theme
* Add GitHub and Google+ social icons support in default theme
* Optimize social icons
* Add ``FEED_ALL_ATOM`` and ``FEED_ALL_RSS`` to generate feeds containing all posts regardless of their language
* Split ``TRANSLATION_FEED`` into ``TRANSLATION_FEED_ATOM`` and ``TRANSLATION_FEED_RSS``
* The different feeds can now be enabled/disabled individually
3.0 (2012-08-08)
==================

View file

@ -93,9 +93,15 @@ Then just make sure to have the template installed in to your theme as
What if I want to disable feed generation?
==========================================
To disable all feed generation set ``FEED_ATOM`` and ``FEED_RSS`` to ``None`` in
your settings. Please note ``None`` and ``''`` are not the same thing. The
word ``None`` should not be surrounded by quotes.
To disable all feed generation, all feed settings should be set to ``None``.
Since other feed settings already defaults to ``None``, you only need to set
the following settings::
FEED_ALL_ATOM = None
CATEGORY_FEED_ATOM = None
Please note that ``None`` and ``''`` are not the same thing. The word ``None``
should not be surrounded by quotes.
I'm getting a warning about feeds generated without SITEURL being set properly
==============================================================================
@ -111,7 +117,7 @@ should result in this warning.
Feeds are still generated when this warning is displayed but may not validate.
My feeds are broken since I upgraded to Pelican 3.0
My feeds are broken since I upgraded to Pelican 3.x
===================================================
Starting in 3.0, some of the FEED setting names were changed to more explicitly
@ -122,6 +128,13 @@ setting names). Here is an exact list of the renamed setting names::
TAG_FEED -> TAG_FEED_ATOM
CATEGORY_FEED -> CATEGORY_FEED_ATOM
Starting in 3.1, the new feed ``FEED_ALL_ATOM`` has been introduced: this
feed will aggregate all posts regardless of their language. It is generated to
``'feeds/all.atom.xml'`` by default and ``FEED_ATOM`` now defaults to ``None``.
The following FEED setting has also been renamed::
TRANSLATION_FEED -> TRANSLATION_FEED_ATOM
Older 2.x themes that referenced the old setting names may not link properly.
In order to rectify this, please update your theme for compatibility with 3.0+
by changing the relevant values in your template files. For an example of

View file

@ -59,11 +59,17 @@ CATEGORY_FEED_RSS :
Idem pour les flux rss (Optionnel);
FEED_ATOM :
Chemin du flux Atom global ;
Chemin du flux Atom global;
FEED_RSS :
Chemin du flux Rss global (Optionnel);
FEED_ALL_ATOM :
Chemin du flux Atom global qui inclut la totalité des posts, indépendamment de la langue;
FEED_ALL_RSS :
Chemin du flux Rss global qui inclut la totalité des posts, indépendamment de la langue (Optionnel);
TAG_FEED_ATOM :
Chemin des flux Atom pour les tags (Optionnel);

View file

@ -303,9 +303,15 @@ Setting name (default value) What does it do?
to define this (e.g., "http://feeds.example.com"). If
you have already explicitly defined SITEURL (see
above) and want to use the same domain for your
feeds, you can just set: `FEED_DOMAIN = SITEURL`
`FEED_ATOM` (``'feeds/all.atom.xml'``) Relative URL to output the Atom feed.
feeds, you can just set: ``FEED_DOMAIN = SITEURL``.
`FEED_ATOM` (``None``, i.e. no Atom feed) Relative URL to output the Atom feed.
`FEED_RSS` (``None``, i.e. no RSS) Relative URL to output the RSS feed.
`FEED_ALL_ATOM` (``'feeds/all.atom.xml'``) Relative URL to output the all posts Atom feed:
this feed will contain all posts regardless of their
language.
`FEED_ALL_RSS` (``None``, i.e. no all RSS) Relative URL to output the all posts RSS feed:
this feed will contain all posts regardless of their
language.
`CATEGORY_FEED_ATOM` ('feeds/%s.atom.xml'[2]_) Where to put the category Atom feeds.
`CATEGORY_FEED_RSS` (``None``, i.e. no RSS) Where to put the category RSS feeds.
`TAG_FEED_ATOM` (``None``, i.e. no tag feed) Relative URL to output the tag Atom feed. It should
@ -315,9 +321,8 @@ Setting name (default value) What does it do?
quantity is unrestricted by default.
================================================ =====================================================
If you don't want to generate some of these feeds, set ``None`` to the
variables above. If you don't want to generate any feeds set both ``FEED_ATOM``
and ``FEED_RSS`` to none.
If you don't want to generate some or any of these feeds, set ``None`` to the
variables above.
.. [2] %s is the name of the category.

View file

@ -200,6 +200,8 @@ Here is a complete list of the feed variables::
FEED_ATOM
FEED_RSS
FEED_ALL_ATOM
FEED_ALL_RSS
CATEGORY_FEED_ATOM
CATEGORY_FEED_RSS
TAG_FEED_ATOM

View file

@ -156,13 +156,6 @@ class ArticlesGenerator(Generator):
def generate_feeds(self, writer):
"""Generate the feeds from the current context, and output files."""
if self.settings.get('FEED_ATOM') is None \
and self.settings.get('FEED_RSS') is None:
return
elif self.settings.get('SITEURL') is '':
logger.warning(
'Feeds generated without SITEURL set properly may not be valid'
)
if self.settings.get('FEED_ATOM'):
writer.write_feed(self.articles, self.context,
@ -172,6 +165,21 @@ class ArticlesGenerator(Generator):
writer.write_feed(self.articles, self.context,
self.settings['FEED_RSS'], feed_type='rss')
if self.settings.get('FEED_ALL_ATOM') or \
self.settings.get('FEED_ALL_RSS'):
all_articles = list(self.articles)
for article in self.articles:
all_articles.extend(article.translations)
all_articles.sort(key=attrgetter('date'), reverse=True)
if self.settings.get('FEED_ALL_ATOM'):
writer.write_feed(all_articles, self.context,
self.settings['FEED_ALL_ATOM'])
if self.settings.get('FEED_ALL_RSS'):
writer.write_feed(all_articles, self.context,
self.settings['FEED_ALL_RSS'], feed_type='rss')
for cat, arts in self.categories:
arts.sort(key=attrgetter('date'), reverse=True)
if self.settings.get('CATEGORY_FEED_ATOM'):

View file

@ -24,7 +24,7 @@ _DEFAULT_CONFIG = {'PATH': '.',
'MARKUP': ('rst', 'md'),
'STATIC_PATHS': ['images', ],
'THEME_STATIC_PATHS': ['static', ],
'FEED_ATOM': 'feeds/all.atom.xml',
'FEED_ALL_ATOM': 'feeds/all.atom.xml',
'CATEGORY_FEED_ATOM': 'feeds/%s.atom.xml',
'TRANSLATION_FEED_ATOM': 'feeds/all-%s.atom.xml',
'FEED_MAX_ITEMS': '',
@ -175,10 +175,21 @@ def configure_settings(settings):
settings['FEED_DOMAIN'] = settings['SITEURL']
# Warn if feeds are generated with both SITEURL & FEED_DOMAIN undefined
if (('FEED_ATOM' in settings) or ('FEED_RSS' in settings)) and (not 'FEED_DOMAIN' in settings):
logger.warn("Since feed URLs should always be absolute, you should specify "
"FEED_DOMAIN in your settings. (e.g., 'FEED_DOMAIN = "
"http://www.example.com')")
feed_keys = ['FEED_ATOM', 'FEED_RSS',
'FEED_ALL_ATOM', 'FEED_ALL_RSS',
'CATEGORY_FEED_ATOM', 'CATEGORY_FEED_RSS',
'TAG_FEED_ATOM', 'TAG_FEED_RSS',
'TRANSLATION_FEED_ATOM', 'TRANSLATION_FEED_RSS',
]
if any(settings.get(k) for k in feed_keys):
if not settings.get('FEED_DOMAIN'):
logger.warn("Since feed URLs should always be absolute, you should specify "
"FEED_DOMAIN in your settings. (e.g., 'FEED_DOMAIN = "
"http://www.example.com')")
if not settings.get('SITEURL'):
logger.warn("Feeds generated without SITEURL set properly may not be valid")
if not 'TIMEZONE' in settings:
logger.warn("No timezone information specified in the settings. Assuming"

View file

@ -4,11 +4,11 @@
<title>{% block title %}{{ SITENAME }}{%endblock%}</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="{{ SITEURL }}/theme/css/{{ CSS_FILE }}" type="text/css" />
{% if FEED_ATOM %}
<link href="{{ FEED_DOMAIN }}/{{ FEED_ATOM }}" type="application/atom+xml" rel="alternate" title="{{ SITENAME }} Atom Feed" />
{% if FEED_ALL_ATOM %}
<link href="{{ FEED_DOMAIN }}/{{ FEED_ALL_ATOM }}" type="application/atom+xml" rel="alternate" title="{{ SITENAME }} Atom Feed" />
{% endif %}
{% if FEED_RSS %}
<link href="{{ FEED_DOMAIN }}/{{ FEED_RSS }}" type="application/rss+xml" rel="alternate" title="{{ SITENAME }} RSS Feed" />
{% if FEED_ALL_RSS %}
<link href="{{ FEED_DOMAIN }}/{{ FEED_ALL_RSS }}" type="application/rss+xml" rel="alternate" title="{{ SITENAME }} RSS Feed" />
{% endif %}
<!--[if IE]>
@ -58,9 +58,9 @@
<div class="social">
<h2>social</h2>
<ul>
<li><a href="{{ FEED_DOMAIN }}/{{ FEED_ATOM }}" type="application/atom+xml" rel="alternate">atom feed</a></li>
{% if FEED_RSS %}
<li><a href="{{ FEED_DOMAIN }}/{{ FEED_RSS }}" type="application/rss+xml" rel="alternate">rss feed</a></li>
<li><a href="{{ FEED_DOMAIN }}/{{ FEED_ALL_ATOM }}" type="application/atom+xml" rel="alternate">atom feed</a></li>
{% if FEED_ALL_RSS %}
<li><a href="{{ FEED_DOMAIN }}/{{ FEED_ALL_RSS }}" type="application/rss+xml" rel="alternate">rss feed</a></li>
{% endif %}
{% for name, link in SOCIAL %}

View file

@ -4,6 +4,12 @@
{% block head %}
<title>{% block title %}{{ SITENAME }}{% endblock title %}</title>
<meta charset="utf-8" />
{% if FEED_ALL_ATOM %}
<link href="{{ FEED_DOMAIN }}/{{ FEED_ALL_ATOM }}" type="application/atom+xml" rel="alternate" title="{{ SITENAME }} Full Atom Feed" />
{% endif %}
{% if FEED_ALL_RSS %}
<link href="{{ FEED_DOMAIN }}/{{ FEED_ALL_RSS }}" type="application/rss+xml" rel="alternate" title="{{ SITENAME }} Full RSS Feed" />
{% endif %}
{% if FEED_ATOM %}
<link href="{{ FEED_DOMAIN }}/{{ FEED_ATOM }}" type="application/atom+xml" rel="alternate" title="{{ SITENAME }} Atom Feed" />
{% endif %}

View file

@ -12,7 +12,7 @@ LOCALE = "C"
DEFAULT_PAGINATION = 4
DEFAULT_DATE = (2012, 03, 02, 14, 01, 01)
FEED_RSS = 'feeds/all.rss.xml'
FEED_ALL_RSS = 'feeds/all.rss.xml'
CATEGORY_FEED_RSS = 'feeds/%s.rss.xml'
LINKS = (('Biologeek', 'http://biologeek.org'),

View file

@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"><title>Alexis' log</title><link href="http://blog.notmyidea.org/" rel="alternate"></link><link href="http://blog.notmyidea.org/feeds/all.atom.xml" rel="self"></link><id>http://blog.notmyidea.org/</id><updated>2012-02-29T00:00:00+01:00</updated><entry><title>Second article</title><link href="http://blog.notmyidea.org/second-article.html" rel="alternate"></link><updated>2012-02-29T00:00:00+01:00</updated><author><name>Alexis Métaireau</name></author><id>tag:blog.notmyidea.org,2012-02-29:second-article.html</id><summary type="html">&lt;p&gt;This is some article, in english&lt;/p&gt;
<feed xmlns="http://www.w3.org/2005/Atom"><title>Alexis' log</title><link href="http://blog.notmyidea.org/" rel="alternate"></link><link href="http://blog.notmyidea.org/feeds/all.atom.xml" rel="self"></link><id>http://blog.notmyidea.org/</id><updated>2012-03-02T14:01:01+01:00</updated><entry><title>Trop bien !</title><link href="http://blog.notmyidea.org/oh-yeah-fr.html" rel="alternate"></link><updated>2012-03-02T14:01:01+01:00</updated><author><name>Alexis Métaireau</name></author><id>tag:blog.notmyidea.org,2012-03-02:oh-yeah-fr.html</id><summary type="html">&lt;p&gt;Et voila du contenu en français&lt;/p&gt;
</summary></entry><entry><title>Second article</title><link href="http://blog.notmyidea.org/second-article.html" rel="alternate"></link><updated>2012-02-29T00:00:00+01:00</updated><author><name>Alexis Métaireau</name></author><id>tag:blog.notmyidea.org,2012-02-29:second-article.html</id><summary type="html">&lt;p&gt;This is some article, in english&lt;/p&gt;
</summary><category term="foo"></category><category term="bar"></category><category term="baz"></category></entry><entry><title>Deuxième article</title><link href="http://blog.notmyidea.org/second-article-fr.html" rel="alternate"></link><updated>2012-02-29T00:00:00+01:00</updated><author><name>Alexis Métaireau</name></author><id>tag:blog.notmyidea.org,2012-02-29:second-article-fr.html</id><summary type="html">&lt;p&gt;Ceci est un article, en français.&lt;/p&gt;
</summary><category term="foo"></category><category term="bar"></category><category term="baz"></category></entry><entry><title>A markdown powered article</title><link href="http://blog.notmyidea.org/a-markdown-powered-article.html" rel="alternate"></link><updated>2011-04-20T00:00:00+02:00</updated><author><name>Alexis Métaireau</name></author><id>tag:blog.notmyidea.org,2011-04-20:a-markdown-powered-article.html</id><summary type="html">&lt;p&gt;You're mutually oblivious.&lt;/p&gt;</summary></entry><entry><title>Article 1</title><link href="http://blog.notmyidea.org/article-1.html" rel="alternate"></link><updated>2011-02-17T00:00:00+01:00</updated><author><name>Alexis Métaireau</name></author><id>tag:blog.notmyidea.org,2011-02-17:article-1.html</id><summary type="html">&lt;p&gt;Article 1&lt;/p&gt;
</summary></entry><entry><title>Article 2</title><link href="http://blog.notmyidea.org/article-2.html" rel="alternate"></link><updated>2011-02-17T00:00:00+01:00</updated><author><name>Alexis Métaireau</name></author><id>tag:blog.notmyidea.org,2011-02-17:article-2.html</id><summary type="html">&lt;p&gt;Article 2&lt;/p&gt;
</summary></entry><entry><title>Article 3</title><link href="http://blog.notmyidea.org/article-3.html" rel="alternate"></link><updated>2011-02-17T00:00:00+01:00</updated><author><name>Alexis Métaireau</name></author><id>tag:blog.notmyidea.org,2011-02-17:article-3.html</id><summary type="html">&lt;p&gt;Article 3&lt;/p&gt;

View file

@ -1,6 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Alexis' log</title><link>http://blog.notmyidea.org/</link><description></description><atom:link href="http://blog.notmyidea.org/feeds/all.rss.xml" rel="self"></atom:link><lastBuildDate>Wed, 29 Feb 2012 00:00:00 +0100</lastBuildDate><item><title>Second article</title><link>http://blog.notmyidea.org/second-article.html</link><description>&lt;p&gt;This is some article, in english&lt;/p&gt;
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Alexis Métaireau</dc:creator><pubDate>Wed, 29 Feb 2012 00:00:00 +0100</pubDate><guid>tag:blog.notmyidea.org,2012-02-29:second-article.html</guid><category>foo</category><category>bar</category><category>baz</category></item><item><title>A markdown powered article</title><link>http://blog.notmyidea.org/a-markdown-powered-article.html</link><description>&lt;p&gt;You're mutually oblivious.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Alexis Métaireau</dc:creator><pubDate>Wed, 20 Apr 2011 00:00:00 +0200</pubDate><guid>tag:blog.notmyidea.org,2011-04-20:a-markdown-powered-article.html</guid></item><item><title>Article 1</title><link>http://blog.notmyidea.org/article-1.html</link><description>&lt;p&gt;Article 1&lt;/p&gt;
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Alexis' log</title><link>http://blog.notmyidea.org/</link><description></description><atom:link href="http://blog.notmyidea.org/feeds/all.rss.xml" rel="self"></atom:link><lastBuildDate>Fri, 02 Mar 2012 14:01:01 +0100</lastBuildDate><item><title>Trop bien !</title><link>http://blog.notmyidea.org/oh-yeah-fr.html</link><description>&lt;p&gt;Et voila du contenu en français&lt;/p&gt;
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Alexis Métaireau</dc:creator><pubDate>Fri, 02 Mar 2012 14:01:01 +0100</pubDate><guid>tag:blog.notmyidea.org,2012-03-02:oh-yeah-fr.html</guid></item><item><title>Second article</title><link>http://blog.notmyidea.org/second-article.html</link><description>&lt;p&gt;This is some article, in english&lt;/p&gt;
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Alexis Métaireau</dc:creator><pubDate>Wed, 29 Feb 2012 00:00:00 +0100</pubDate><guid>tag:blog.notmyidea.org,2012-02-29:second-article.html</guid><category>foo</category><category>bar</category><category>baz</category></item><item><title>Deuxième article</title><link>http://blog.notmyidea.org/second-article-fr.html</link><description>&lt;p&gt;Ceci est un article, en français.&lt;/p&gt;
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Alexis Métaireau</dc:creator><pubDate>Wed, 29 Feb 2012 00:00:00 +0100</pubDate><guid>tag:blog.notmyidea.org,2012-02-29:second-article-fr.html</guid><category>foo</category><category>bar</category><category>baz</category></item><item><title>A markdown powered article</title><link>http://blog.notmyidea.org/a-markdown-powered-article.html</link><description>&lt;p&gt;You're mutually oblivious.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Alexis Métaireau</dc:creator><pubDate>Wed, 20 Apr 2011 00:00:00 +0200</pubDate><guid>tag:blog.notmyidea.org,2011-04-20:a-markdown-powered-article.html</guid></item><item><title>Article 1</title><link>http://blog.notmyidea.org/article-1.html</link><description>&lt;p&gt;Article 1&lt;/p&gt;
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Alexis Métaireau</dc:creator><pubDate>Thu, 17 Feb 2011 00:00:00 +0100</pubDate><guid>tag:blog.notmyidea.org,2011-02-17:article-1.html</guid></item><item><title>Article 2</title><link>http://blog.notmyidea.org/article-2.html</link><description>&lt;p&gt;Article 2&lt;/p&gt;
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Alexis Métaireau</dc:creator><pubDate>Thu, 17 Feb 2011 00:00:00 +0100</pubDate><guid>tag:blog.notmyidea.org,2011-02-17:article-2.html</guid></item><item><title>Article 3</title><link>http://blog.notmyidea.org/article-3.html</link><description>&lt;p&gt;Article 3&lt;/p&gt;
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Alexis Métaireau</dc:creator><pubDate>Thu, 17 Feb 2011 00:00:00 +0100</pubDate><guid>tag:blog.notmyidea.org,2011-02-17:article-3.html</guid></item><item><title>This is a super article !</title><link>http://blog.notmyidea.org/this-is-a-super-article.html</link><description>&lt;p&gt;Some content here !&lt;/p&gt;

View file

@ -50,14 +50,14 @@ class TestArticlesGenerator(unittest.TestCase):
def test_generate_feeds(self):
generator = ArticlesGenerator(None, {'FEED_ATOM': _DEFAULT_CONFIG['FEED_ATOM']},
generator = ArticlesGenerator(None, {'FEED_ALL_ATOM': _DEFAULT_CONFIG['FEED_ALL_ATOM']},
None, _DEFAULT_CONFIG['THEME'], None,
_DEFAULT_CONFIG['MARKUP'])
writer = MagicMock()
generator.generate_feeds(writer)
writer.write_feed.assert_called_with([], None, 'feeds/all.atom.xml')
generator = ArticlesGenerator(None, {'FEED_ATOM': None}, None,
generator = ArticlesGenerator(None, {'FEED_ALL_ATOM': None}, None,
_DEFAULT_CONFIG['THEME'], None, None)
writer = MagicMock()
generator.generate_feeds(writer)