mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Merge pull request #2238 from mosra/feed-urls
Feed URL settings, making feeds aware of absolute URLs
This commit is contained in:
commit
81b7e7481f
6 changed files with 161 additions and 35 deletions
|
|
@ -827,46 +827,95 @@ the ``TAG_FEED_ATOM`` and ``TAG_FEED_RSS`` settings:
|
||||||
|
|
||||||
.. data:: FEED_ATOM = None, i.e. no Atom feed
|
.. data:: FEED_ATOM = None, i.e. no Atom feed
|
||||||
|
|
||||||
Relative URL to output the Atom feed.
|
The location to save the Atom feed.
|
||||||
|
|
||||||
|
.. data:: FEED_ATOM_URL = None
|
||||||
|
|
||||||
|
Relative URL of the Atom feed. If not set, ``FEED_ATOM`` is used both for
|
||||||
|
save location and URL.
|
||||||
|
|
||||||
.. data:: FEED_RSS = None, i.e. no RSS
|
.. data:: FEED_RSS = None, i.e. no RSS
|
||||||
|
|
||||||
Relative URL to output the RSS feed.
|
The location to save the RSS feed.
|
||||||
|
|
||||||
|
.. data:: FEED_RSS_URL = None
|
||||||
|
|
||||||
|
Relative URL of the RSS feed. If not set, ``FEED_RSS`` is used both for save
|
||||||
|
location and URL.
|
||||||
|
|
||||||
.. data:: FEED_ALL_ATOM = 'feeds/all.atom.xml'
|
.. data:: FEED_ALL_ATOM = 'feeds/all.atom.xml'
|
||||||
|
|
||||||
Relative URL to output the all-posts Atom feed: this feed will contain all
|
The location to save the all-posts Atom feed: this feed will contain all
|
||||||
posts regardless of their language.
|
posts regardless of their language.
|
||||||
|
|
||||||
|
.. data:: FEED_ALL_ATOM_URL = None
|
||||||
|
|
||||||
|
Relative URL of the all-posts Atom feed. If not set, ``FEED_ALL_ATOM`` is
|
||||||
|
used both for save location and URL.
|
||||||
|
|
||||||
.. data:: FEED_ALL_RSS = None, i.e. no all-posts RSS
|
.. data:: FEED_ALL_RSS = None, i.e. no all-posts RSS
|
||||||
|
|
||||||
Relative URL to output the all-posts RSS feed: this feed will contain all
|
The location to save the the all-posts RSS feed: this feed will contain all
|
||||||
posts regardless of their language.
|
posts regardless of their language.
|
||||||
|
|
||||||
|
.. data:: FEED_ALL_RSS_URL = None
|
||||||
|
|
||||||
|
Relative URL of the all-posts RSS feed. If not set, ``FEED_ALL_RSS`` is used
|
||||||
|
both for save location and URL.
|
||||||
|
|
||||||
.. data:: CATEGORY_FEED_ATOM = 'feeds/%s.atom.xml'
|
.. data:: CATEGORY_FEED_ATOM = 'feeds/%s.atom.xml'
|
||||||
|
|
||||||
Where to put the category Atom feeds. [2]_
|
The location to save the category Atom feeds. [2]_
|
||||||
|
|
||||||
|
.. data:: CATEGORY_FEED_ATOM_URL = None
|
||||||
|
|
||||||
|
Relative URL of the category Atom feeds, including the ``%s`` placeholder.
|
||||||
|
[2]_ If not set, ``CATEGORY_FEED_ATOM`` is used both for save location and
|
||||||
|
URL.
|
||||||
|
|
||||||
.. data:: CATEGORY_FEED_RSS = None, i.e. no RSS
|
.. data:: CATEGORY_FEED_RSS = None, i.e. no RSS
|
||||||
|
|
||||||
Where to put the category RSS feeds.
|
The location to save the category RSS feeds, including the ``%s``
|
||||||
|
placeholder. [2]_
|
||||||
|
|
||||||
|
.. data:: CATEGORY_FEED_RSS_URL = None
|
||||||
|
|
||||||
|
Relative URL of the category RSS feeds, including the ``%s`` placeholder.
|
||||||
|
[2]_ If not set, ``CATEGORY_FEED_RSS`` is used both for save location and
|
||||||
|
URL.
|
||||||
|
|
||||||
.. data:: AUTHOR_FEED_ATOM = 'feeds/%s.atom.xml'
|
.. data:: AUTHOR_FEED_ATOM = 'feeds/%s.atom.xml'
|
||||||
|
|
||||||
Where to put the author Atom feeds. [2]_
|
The location to save the author Atom feeds. [2]_
|
||||||
|
|
||||||
|
.. data:: AUTHOR_FEED_ATOM_URL = None
|
||||||
|
|
||||||
|
Relative URL of the author Atom feeds, including the ``%s`` placeholder.
|
||||||
|
[2]_ If not set, ``AUTHOR_FEED_ATOM`` is used both for save location and
|
||||||
|
URL.
|
||||||
|
|
||||||
.. data:: AUTHOR_FEED_RSS = 'feeds/%s.rss.xml'
|
.. data:: AUTHOR_FEED_RSS = 'feeds/%s.rss.xml'
|
||||||
|
|
||||||
Where to put the author RSS feeds. [2]_
|
The location to save the author RSS feeds. [2]_
|
||||||
|
|
||||||
|
.. data:: AUTHOR_FEED_RSS_URL = None
|
||||||
|
|
||||||
|
Relative URL of the author RSS feeds, including the ``%s`` placeholder. [2]_
|
||||||
|
If not set, ``AUTHOR_FEED_RSS`` is used both for save location and URL.
|
||||||
|
|
||||||
.. data:: TAG_FEED_ATOM = None, i.e. no tag feed
|
.. data:: TAG_FEED_ATOM = None, i.e. no tag feed
|
||||||
|
|
||||||
Relative URL to output the tag Atom feed. It should be defined using a "%s"
|
The location to save the tag Atom feed, including the ``%s`` placeholder.
|
||||||
match in the tag name.
|
[2]_
|
||||||
|
|
||||||
|
.. data:: TAG_FEED_ATOM_URL = None
|
||||||
|
|
||||||
|
Relative URL of the tag Atom feed, including the ``%s`` placeholder. [2]_
|
||||||
|
|
||||||
.. data:: TAG_FEED_RSS = None, i.e. no RSS tag feed
|
.. data:: TAG_FEED_RSS = None, i.e. no RSS tag feed
|
||||||
|
|
||||||
Relative URL to output the tag RSS feed
|
Relative URL to output the tag RSS feed, including the ``%s`` placeholder.
|
||||||
|
If not set, ``TAG_FEED_RSS`` is used both for save location and URL.
|
||||||
|
|
||||||
.. data:: FEED_MAX_ITEMS
|
.. data:: FEED_MAX_ITEMS
|
||||||
|
|
||||||
|
|
@ -881,7 +930,7 @@ the ``TAG_FEED_ATOM`` and ``TAG_FEED_RSS`` settings:
|
||||||
|
|
||||||
If you don't want to generate some or any of these feeds, set the above variables to ``None``.
|
If you don't want to generate some or any of these feeds, set the above variables to ``None``.
|
||||||
|
|
||||||
.. [2] %s is the name of the category.
|
.. [2] ``%s`` is replaced by name of the category / author / tag.
|
||||||
|
|
||||||
|
|
||||||
FeedBurner
|
FeedBurner
|
||||||
|
|
@ -964,12 +1013,24 @@ more information.
|
||||||
|
|
||||||
.. data:: TRANSLATION_FEED_ATOM = 'feeds/all-%s.atom.xml'
|
.. data:: TRANSLATION_FEED_ATOM = 'feeds/all-%s.atom.xml'
|
||||||
|
|
||||||
Where to put the Atom feed for translations. [3]_
|
The location to save the Atom feed for translations. [3]_
|
||||||
|
|
||||||
|
.. data:: TRANSLATION_FEED_ATOM_URL = None
|
||||||
|
|
||||||
|
Relative URL of the Atom feed for translations, including the ``%s``
|
||||||
|
placeholder. [3]_ If not set, ``TRANSLATION_FEED_ATOM`` is used both for
|
||||||
|
save location and URL.
|
||||||
|
|
||||||
.. data:: TRANSLATION_FEED_RSS = None, i.e. no RSS
|
.. data:: TRANSLATION_FEED_RSS = None, i.e. no RSS
|
||||||
|
|
||||||
Where to put the RSS feed for translations.
|
Where to put the RSS feed for translations.
|
||||||
|
|
||||||
|
.. data:: TRANSLATION_FEED_RSS_URL = None
|
||||||
|
|
||||||
|
Relative URL of the RSS feed for translations, including the ``%s``
|
||||||
|
placeholder. [3]_ If not set, ``TRANSLATION_FEED_RSS`` is used both for save
|
||||||
|
location and URL.
|
||||||
|
|
||||||
.. [3] %s is the language
|
.. [3] %s is the language
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -294,11 +294,16 @@ class ArticlesGenerator(CachingGenerator):
|
||||||
|
|
||||||
if self.settings.get('FEED_ATOM'):
|
if self.settings.get('FEED_ATOM'):
|
||||||
writer.write_feed(self.articles, self.context,
|
writer.write_feed(self.articles, self.context,
|
||||||
self.settings['FEED_ATOM'])
|
self.settings['FEED_ATOM'],
|
||||||
|
self.settings.get('FEED_ATOM_URL',
|
||||||
|
self.settings['FEED_ATOM']))
|
||||||
|
|
||||||
if self.settings.get('FEED_RSS'):
|
if self.settings.get('FEED_RSS'):
|
||||||
writer.write_feed(self.articles, self.context,
|
writer.write_feed(self.articles, self.context,
|
||||||
self.settings['FEED_RSS'], feed_type='rss')
|
self.settings['FEED_RSS'],
|
||||||
|
self.settings.get('FEED_RSS_URL',
|
||||||
|
self.settings['FEED_RSS']),
|
||||||
|
feed_type='rss')
|
||||||
|
|
||||||
if (self.settings.get('FEED_ALL_ATOM') or
|
if (self.settings.get('FEED_ALL_ATOM') or
|
||||||
self.settings.get('FEED_ALL_RSS')):
|
self.settings.get('FEED_ALL_RSS')):
|
||||||
|
|
@ -309,11 +314,17 @@ class ArticlesGenerator(CachingGenerator):
|
||||||
|
|
||||||
if self.settings.get('FEED_ALL_ATOM'):
|
if self.settings.get('FEED_ALL_ATOM'):
|
||||||
writer.write_feed(all_articles, self.context,
|
writer.write_feed(all_articles, self.context,
|
||||||
self.settings['FEED_ALL_ATOM'])
|
self.settings['FEED_ALL_ATOM'],
|
||||||
|
self.settings.get(
|
||||||
|
'FEED_ALL_ATOM_URL',
|
||||||
|
self.settings['FEED_ALL_ATOM']))
|
||||||
|
|
||||||
if self.settings.get('FEED_ALL_RSS'):
|
if self.settings.get('FEED_ALL_RSS'):
|
||||||
writer.write_feed(all_articles, self.context,
|
writer.write_feed(all_articles, self.context,
|
||||||
self.settings['FEED_ALL_RSS'],
|
self.settings['FEED_ALL_RSS'],
|
||||||
|
self.settings.get(
|
||||||
|
'FEED_ALL_RSS_URL',
|
||||||
|
self.settings['FEED_ALL_RSS']),
|
||||||
feed_type='rss')
|
feed_type='rss')
|
||||||
|
|
||||||
for cat, arts in self.categories:
|
for cat, arts in self.categories:
|
||||||
|
|
@ -321,11 +332,19 @@ class ArticlesGenerator(CachingGenerator):
|
||||||
if self.settings.get('CATEGORY_FEED_ATOM'):
|
if self.settings.get('CATEGORY_FEED_ATOM'):
|
||||||
writer.write_feed(arts, self.context,
|
writer.write_feed(arts, self.context,
|
||||||
self.settings['CATEGORY_FEED_ATOM']
|
self.settings['CATEGORY_FEED_ATOM']
|
||||||
|
% cat.slug,
|
||||||
|
self.settings.get(
|
||||||
|
'CATEGORY_FEED_ATOM_URL',
|
||||||
|
self.settings['CATEGORY_FEED_ATOM'])
|
||||||
% cat.slug, feed_title=cat.name)
|
% cat.slug, feed_title=cat.name)
|
||||||
|
|
||||||
if self.settings.get('CATEGORY_FEED_RSS'):
|
if self.settings.get('CATEGORY_FEED_RSS'):
|
||||||
writer.write_feed(arts, self.context,
|
writer.write_feed(arts, self.context,
|
||||||
self.settings['CATEGORY_FEED_RSS']
|
self.settings['CATEGORY_FEED_RSS']
|
||||||
|
% cat.slug,
|
||||||
|
self.settings.get(
|
||||||
|
'CATEGORY_FEED_RSS_URL',
|
||||||
|
self.settings['CATEGORY_FEED_RSS'])
|
||||||
% cat.slug, feed_title=cat.name,
|
% cat.slug, feed_title=cat.name,
|
||||||
feed_type='rss')
|
feed_type='rss')
|
||||||
|
|
||||||
|
|
@ -334,11 +353,19 @@ class ArticlesGenerator(CachingGenerator):
|
||||||
if self.settings.get('AUTHOR_FEED_ATOM'):
|
if self.settings.get('AUTHOR_FEED_ATOM'):
|
||||||
writer.write_feed(arts, self.context,
|
writer.write_feed(arts, self.context,
|
||||||
self.settings['AUTHOR_FEED_ATOM']
|
self.settings['AUTHOR_FEED_ATOM']
|
||||||
|
% auth.slug,
|
||||||
|
self.settings.get(
|
||||||
|
'AUTHOR_FEED_ATOM_URL',
|
||||||
|
self.settings['AUTHOR_FEED_ATOM'])
|
||||||
% auth.slug, feed_title=auth.name)
|
% auth.slug, feed_title=auth.name)
|
||||||
|
|
||||||
if self.settings.get('AUTHOR_FEED_RSS'):
|
if self.settings.get('AUTHOR_FEED_RSS'):
|
||||||
writer.write_feed(arts, self.context,
|
writer.write_feed(arts, self.context,
|
||||||
self.settings['AUTHOR_FEED_RSS']
|
self.settings['AUTHOR_FEED_RSS']
|
||||||
|
% auth.slug,
|
||||||
|
self.settings.get(
|
||||||
|
'AUTHOR_FEED_RSS_URL',
|
||||||
|
self.settings['AUTHOR_FEED_RSS'])
|
||||||
% auth.slug, feed_title=auth.name,
|
% auth.slug, feed_title=auth.name,
|
||||||
feed_type='rss')
|
feed_type='rss')
|
||||||
|
|
||||||
|
|
@ -349,12 +376,20 @@ class ArticlesGenerator(CachingGenerator):
|
||||||
if self.settings.get('TAG_FEED_ATOM'):
|
if self.settings.get('TAG_FEED_ATOM'):
|
||||||
writer.write_feed(arts, self.context,
|
writer.write_feed(arts, self.context,
|
||||||
self.settings['TAG_FEED_ATOM']
|
self.settings['TAG_FEED_ATOM']
|
||||||
|
% tag.slug,
|
||||||
|
self.settings.get(
|
||||||
|
'TAG_FEED_ATOM_URL',
|
||||||
|
self.settings['TAG_FEED_ATOM'])
|
||||||
% tag.slug, feed_title=tag.name)
|
% tag.slug, feed_title=tag.name)
|
||||||
|
|
||||||
if self.settings.get('TAG_FEED_RSS'):
|
if self.settings.get('TAG_FEED_RSS'):
|
||||||
writer.write_feed(arts, self.context,
|
writer.write_feed(arts, self.context,
|
||||||
self.settings['TAG_FEED_RSS'] % tag.slug,
|
self.settings['TAG_FEED_RSS'] % tag.slug,
|
||||||
feed_title=tag.name, feed_type='rss')
|
self.settings.get(
|
||||||
|
'TAG_FEED_RSS_URL',
|
||||||
|
self.settings['TAG_FEED_RSS'])
|
||||||
|
% tag.slug, feed_title=tag.name,
|
||||||
|
feed_type='rss')
|
||||||
|
|
||||||
if (self.settings.get('TRANSLATION_FEED_ATOM') or
|
if (self.settings.get('TRANSLATION_FEED_ATOM') or
|
||||||
self.settings.get('TRANSLATION_FEED_RSS')):
|
self.settings.get('TRANSLATION_FEED_RSS')):
|
||||||
|
|
@ -367,11 +402,17 @@ class ArticlesGenerator(CachingGenerator):
|
||||||
if self.settings.get('TRANSLATION_FEED_ATOM'):
|
if self.settings.get('TRANSLATION_FEED_ATOM'):
|
||||||
writer.write_feed(
|
writer.write_feed(
|
||||||
items, self.context,
|
items, self.context,
|
||||||
self.settings['TRANSLATION_FEED_ATOM'] % lang)
|
self.settings['TRANSLATION_FEED_ATOM'] % lang,
|
||||||
|
self.settings.get(
|
||||||
|
'TRANSLATION_FEED_ATOM_URL',
|
||||||
|
self.settings['TRANSLATION_FEED_ATOM']) % lang)
|
||||||
if self.settings.get('TRANSLATION_FEED_RSS'):
|
if self.settings.get('TRANSLATION_FEED_RSS'):
|
||||||
writer.write_feed(
|
writer.write_feed(
|
||||||
items, self.context,
|
items, self.context,
|
||||||
self.settings['TRANSLATION_FEED_RSS'] % lang,
|
self.settings['TRANSLATION_FEED_RSS'] % lang,
|
||||||
|
self.settings.get(
|
||||||
|
'TRANSLATION_FEED_RSS_URL',
|
||||||
|
self.settings['TRANSLATION_FEED_RSS']) % lang,
|
||||||
feed_type='rss')
|
feed_type='rss')
|
||||||
|
|
||||||
def generate_articles(self, write):
|
def generate_articles(self, write):
|
||||||
|
|
|
||||||
|
|
@ -211,6 +211,7 @@ class TestArticlesGenerator(unittest.TestCase):
|
||||||
writer = MagicMock()
|
writer = MagicMock()
|
||||||
generator.generate_feeds(writer)
|
generator.generate_feeds(writer)
|
||||||
writer.write_feed.assert_called_with([], settings,
|
writer.write_feed.assert_called_with([], settings,
|
||||||
|
'feeds/all.atom.xml',
|
||||||
'feeds/all.atom.xml')
|
'feeds/all.atom.xml')
|
||||||
|
|
||||||
generator = ArticlesGenerator(
|
generator = ArticlesGenerator(
|
||||||
|
|
@ -220,6 +221,20 @@ class TestArticlesGenerator(unittest.TestCase):
|
||||||
generator.generate_feeds(writer)
|
generator.generate_feeds(writer)
|
||||||
self.assertFalse(writer.write_feed.called)
|
self.assertFalse(writer.write_feed.called)
|
||||||
|
|
||||||
|
@unittest.skipUnless(MagicMock, 'Needs Mock module')
|
||||||
|
def test_generate_feeds_override_url(self):
|
||||||
|
settings = get_settings()
|
||||||
|
settings['CACHE_PATH'] = self.temp_cache
|
||||||
|
settings['FEED_ALL_ATOM_URL'] = 'feeds/atom/all/'
|
||||||
|
generator = ArticlesGenerator(
|
||||||
|
context=settings, settings=settings,
|
||||||
|
path=None, theme=settings['THEME'], output_path=None)
|
||||||
|
writer = MagicMock()
|
||||||
|
generator.generate_feeds(writer)
|
||||||
|
writer.write_feed.assert_called_with([], settings,
|
||||||
|
'feeds/all.atom.xml',
|
||||||
|
'feeds/atom/all/')
|
||||||
|
|
||||||
def test_generate_context(self):
|
def test_generate_context(self):
|
||||||
articles_expected = [
|
articles_expected = [
|
||||||
['Article title', 'published', 'Default', 'article'],
|
['Article title', 'published', 'Default', 'article'],
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,10 @@
|
||||||
<title>{% block title %}{{ SITENAME }}{%endblock%}</title>
|
<title>{% block title %}{{ SITENAME }}{%endblock%}</title>
|
||||||
<link rel="stylesheet" href="{{ SITEURL }}/{{ THEME_STATIC_DIR }}/css/{{ CSS_FILE }}" />
|
<link rel="stylesheet" href="{{ SITEURL }}/{{ THEME_STATIC_DIR }}/css/{{ CSS_FILE }}" />
|
||||||
{% if FEED_ALL_ATOM %}
|
{% if FEED_ALL_ATOM %}
|
||||||
<link href="{{ FEED_DOMAIN }}/{{ FEED_ALL_ATOM }}" type="application/atom+xml" rel="alternate" title="{{ SITENAME }} Atom Feed" />
|
<link href="{{ FEED_DOMAIN }}/{% if FEED_ALL_ATOM_URL %}{{ FEED_ALL_ATOM_URL }}{% else %}{{ FEED_ALL_ATOM }}{% endif %}" type="application/atom+xml" rel="alternate" title="{{ SITENAME }} Atom Feed" />
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if FEED_ALL_RSS %}
|
{% if FEED_ALL_RSS %}
|
||||||
<link href="{{ FEED_DOMAIN }}/{{ FEED_ALL_RSS }}" type="application/rss+xml" rel="alternate" title="{{ SITENAME }} RSS Feed" />
|
<link href="{{ FEED_DOMAIN }}/{% if FEED_ALL_RSS_URL %}{{ FEED_ALL_RSS_URL }}{% else %}{{ FEED_ALL_RSS }}{% endif %}" type="application/rss+xml" rel="alternate" title="{{ SITENAME }} RSS Feed" />
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
|
@ -50,10 +50,10 @@
|
||||||
<h2>{{ SOCIAL_WIDGET_NAME | default('social') }}</h2>
|
<h2>{{ SOCIAL_WIDGET_NAME | default('social') }}</h2>
|
||||||
<ul>
|
<ul>
|
||||||
{% if FEED_ALL_ATOM %}
|
{% if FEED_ALL_ATOM %}
|
||||||
<li><a href="{{ FEED_DOMAIN }}/{{ FEED_ALL_ATOM }}" type="application/atom+xml" rel="alternate">atom feed</a></li>
|
<li><a href="{{ FEED_DOMAIN }}/{% if FEED_ALL_ATOM_URL %}{{ FEED_ALL_ATOM_URL }}{% else %}{{ FEED_ALL_ATOM }}{% endif %}" type="application/atom+xml" rel="alternate">atom feed</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if FEED_ALL_RSS %}
|
{% if FEED_ALL_RSS %}
|
||||||
<li><a href="{{ FEED_DOMAIN }}/{{ FEED_ALL_RSS }}" type="application/rss+xml" rel="alternate">rss feed</a></li>
|
<li><a href="{{ FEED_DOMAIN }}/{% if FEED_ALL_RSS_URL %}{{ FEED_ALL_RSS_URL }}{% else %}{{ FEED_ALL_RSS }}{% endif %}" type="application/rss+xml" rel="alternate">rss feed</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% for name, link in SOCIAL %}
|
{% for name, link in SOCIAL %}
|
||||||
|
|
|
||||||
|
|
@ -5,28 +5,28 @@
|
||||||
<title>{% block title %}{{ SITENAME }}{% endblock title %}</title>
|
<title>{% block title %}{{ SITENAME }}{% endblock title %}</title>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
{% if FEED_ALL_ATOM %}
|
{% if FEED_ALL_ATOM %}
|
||||||
<link href="{{ FEED_DOMAIN }}/{{ FEED_ALL_ATOM }}" type="application/atom+xml" rel="alternate" title="{{ SITENAME }} Full Atom Feed" />
|
<link href="{{ FEED_DOMAIN }}/{% if FEED_ALL_ATOM_URL %}{{ FEED_ALL_ATOM_URL }}{% else %}{{ FEED_ALL_ATOM }}{% endif %}" type="application/atom+xml" rel="alternate" title="{{ SITENAME }} Full Atom Feed" />
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if FEED_ALL_RSS %}
|
{% if FEED_ALL_RSS %}
|
||||||
<link href="{{ FEED_DOMAIN }}/{{ FEED_ALL_RSS }}" type="application/rss+xml" rel="alternate" title="{{ SITENAME }} Full RSS Feed" />
|
<link href="{{ FEED_DOMAIN }}/{% if FEED_ALL_RSS_URL %}{{ FEED_ALL_RSS_URL }}{% else %}{{ FEED_ALL_RSS }}{% endif %}" type="application/rss+xml" rel="alternate" title="{{ SITENAME }} Full RSS Feed" />
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if FEED_ATOM %}
|
{% if FEED_ATOM %}
|
||||||
<link href="{{ FEED_DOMAIN }}/{{ FEED_ATOM }}" type="application/atom+xml" rel="alternate" title="{{ SITENAME }} Atom Feed" />
|
<link href="{{ FEED_DOMAIN }}/{%if FEED_ATOM_URL %}{{ FEED_ATOM_URL }}{% else %}{{ FEED_ATOM }}{% endif %}" type="application/atom+xml" rel="alternate" title="{{ SITENAME }} Atom Feed" />
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if FEED_RSS %}
|
{% if FEED_RSS %}
|
||||||
<link href="{{ FEED_DOMAIN }}/{{ FEED_RSS }}" type="application/rss+xml" rel="alternate" title="{{ SITENAME }} RSS Feed" />
|
<link href="{{ FEED_DOMAIN }}/{% if FEED_RSS_URL %}{{ FEED_RSS_URL }}{% else %}{{ FEED_RSS }}{% endif %}" type="application/rss+xml" rel="alternate" title="{{ SITENAME }} RSS Feed" />
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if CATEGORY_FEED_ATOM and category %}
|
{% if CATEGORY_FEED_ATOM and category %}
|
||||||
<link href="{{ FEED_DOMAIN }}/{{ CATEGORY_FEED_ATOM|format(category.slug) }}" type="application/atom+xml" rel="alternate" title="{{ SITENAME }} Categories Atom Feed" />
|
<link href="{{ FEED_DOMAIN }}/{% if CATEGORY_FEED_ATOM_URL %}{{ CATEGORY_FEED_ATOM_URL|format(category.slug) }}{% else %}{{ CATEGORY_FEED_ATOM|format(category.slug) }}{% endif %}" type="application/atom+xml" rel="alternate" title="{{ SITENAME }} Categories Atom Feed" />
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if CATEGORY_FEED_RSS and category %}
|
{% if CATEGORY_FEED_RSS and category %}
|
||||||
<link href="{{ FEED_DOMAIN }}/{{ CATEGORY_FEED_RSS|format(category.slug) }}" type="application/rss+xml" rel="alternate" title="{{ SITENAME }} Categories RSS Feed" />
|
<link href="{{ FEED_DOMAIN }}/{% if CATEGORY_FEED_RSS_URL %}{{ CATEGORY_FEED_RSS_URL|format(category.slug) }}{% else %}{{ CATEGORY_FEED_RSS|format(category.slug) }}{% endif %}" type="application/rss+xml" rel="alternate" title="{{ SITENAME }} Categories RSS Feed" />
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if TAG_FEED_ATOM and tag %}
|
{% if TAG_FEED_ATOM and tag %}
|
||||||
<link href="{{ FEED_DOMAIN }}/{{ TAG_FEED_ATOM|format(tag.slug) }}" type="application/atom+xml" rel="alternate" title="{{ SITENAME }} Tags Atom Feed" />
|
<link href="{{ FEED_DOMAIN }}/{% if TAG_FEED_ATOM_URL %}{{ TAG_FEED_ATOM_URL|format(tag.slug) }}{% else %}{{ TAG_FEED_ATOM|format(tag.slug) }}{% endif %}" type="application/atom+xml" rel="alternate" title="{{ SITENAME }} Tags Atom Feed" />
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if TAG_FEED_RSS and tag %}
|
{% if TAG_FEED_RSS and tag %}
|
||||||
<link href="{{ FEED_DOMAIN }}/{{ TAG_FEED_RSS|format(tag.slug) }}" type="application/rss+xml" rel="alternate" title="{{ SITENAME }} Tags RSS Feed" />
|
<link href="{{ FEED_DOMAIN }}/{% if TAG_FEED_RSS_URL %}{{ TAG_FEED_RSS_URL|format(tag.slug) }}{% else %}{{ TAG_FEED_RSS|format(tag.slug) }}{% endif %}" type="application/rss+xml" rel="alternate" title="{{ SITENAME }} Tags RSS Feed" />
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endblock head %}
|
{% endblock head %}
|
||||||
</head>
|
</head>
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ from feedgenerator import Atom1Feed, Rss201rev2Feed, get_tag_uri
|
||||||
from jinja2 import Markup
|
from jinja2 import Markup
|
||||||
|
|
||||||
import six
|
import six
|
||||||
|
from six.moves.urllib.parse import urljoin
|
||||||
|
|
||||||
from pelican import signals
|
from pelican import signals
|
||||||
from pelican.paginator import Paginator
|
from pelican.paginator import Paginator
|
||||||
|
|
@ -30,6 +31,13 @@ class Writer(object):
|
||||||
self._written_files = set()
|
self._written_files = set()
|
||||||
self._overridden_files = set()
|
self._overridden_files = set()
|
||||||
|
|
||||||
|
# See Content._link_replacer for details
|
||||||
|
if self.settings['RELATIVE_URLS']:
|
||||||
|
self.urljoiner = os.path.join
|
||||||
|
else:
|
||||||
|
self.urljoiner = lambda base, url: urljoin(
|
||||||
|
base if base.endswith('/') else base + '/', url)
|
||||||
|
|
||||||
def _create_new_feed(self, feed_type, feed_title, context):
|
def _create_new_feed(self, feed_type, feed_title, context):
|
||||||
feed_class = Rss201rev2Feed if feed_type == 'rss' else Atom1Feed
|
feed_class = Rss201rev2Feed if feed_type == 'rss' else Atom1Feed
|
||||||
if feed_title:
|
if feed_title:
|
||||||
|
|
@ -45,9 +53,8 @@ class Writer(object):
|
||||||
return feed
|
return feed
|
||||||
|
|
||||||
def _add_item_to_the_feed(self, feed, item):
|
def _add_item_to_the_feed(self, feed, item):
|
||||||
|
|
||||||
title = Markup(item.title).striptags()
|
title = Markup(item.title).striptags()
|
||||||
link = '%s/%s' % (self.site_url, item.url)
|
link = self.urljoiner(self.site_url, item.url)
|
||||||
is_rss = isinstance(feed, Rss201rev2Feed)
|
is_rss = isinstance(feed, Rss201rev2Feed)
|
||||||
if not is_rss or self.settings.get('RSS_FEED_SUMMARY_ONLY'):
|
if not is_rss or self.settings.get('RSS_FEED_SUMMARY_ONLY'):
|
||||||
description = item.summary
|
description = item.summary
|
||||||
|
|
@ -90,8 +97,8 @@ class Writer(object):
|
||||||
self._written_files.add(filename)
|
self._written_files.add(filename)
|
||||||
return open(filename, 'w', encoding=encoding)
|
return open(filename, 'w', encoding=encoding)
|
||||||
|
|
||||||
def write_feed(self, elements, context, path=None, feed_type='atom',
|
def write_feed(self, elements, context, path=None, url=None,
|
||||||
override_output=False, feed_title=None):
|
feed_type='atom', override_output=False, feed_title=None):
|
||||||
"""Generate a feed with the list of articles provided
|
"""Generate a feed with the list of articles provided
|
||||||
|
|
||||||
Return the feed. If no path or output_path is specified, just
|
Return the feed. If no path or output_path is specified, just
|
||||||
|
|
@ -100,6 +107,8 @@ class Writer(object):
|
||||||
:param elements: the articles to put on the feed.
|
:param elements: the articles to put on the feed.
|
||||||
:param context: the context to get the feed metadata.
|
:param context: the context to get the feed metadata.
|
||||||
:param path: the path to output.
|
:param path: the path to output.
|
||||||
|
:param url: the publicly visible feed URL; if None, path is used
|
||||||
|
instead
|
||||||
:param feed_type: the feed type to use (atom or rss)
|
:param feed_type: the feed type to use (atom or rss)
|
||||||
:param override_output: boolean telling if we can override previous
|
:param override_output: boolean telling if we can override previous
|
||||||
output with the same name (and if next files written with the same
|
output with the same name (and if next files written with the same
|
||||||
|
|
@ -113,7 +122,7 @@ class Writer(object):
|
||||||
'SITEURL', path_to_url(get_relative_path(path)))
|
'SITEURL', path_to_url(get_relative_path(path)))
|
||||||
|
|
||||||
self.feed_domain = context.get('FEED_DOMAIN')
|
self.feed_domain = context.get('FEED_DOMAIN')
|
||||||
self.feed_url = '{}/{}'.format(self.feed_domain, path)
|
self.feed_url = self.urljoiner(self.feed_domain, url if url else path)
|
||||||
|
|
||||||
feed = self._create_new_feed(feed_type, feed_title, context)
|
feed = self._create_new_feed(feed_type, feed_title, context)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue