forked from github/pelican
Convert FEED settings from %s to {slug} redux (#2432)
* Convert FEED settings from `%s` to `{slug}` redux
Closes #2106, Closes #2383
This commit is contained in:
parent
682b0b6711
commit
3a0add4b6e
10 changed files with 165 additions and 102 deletions
1
THANKS
1
THANKS
|
|
@ -155,6 +155,7 @@ Tshepang Lekhonkhobe
|
|||
Valentin-Costel Hăloiu
|
||||
Vlad Niculae
|
||||
William Light
|
||||
William Minchin
|
||||
Wladislaw Merezhko
|
||||
W. Trevor King
|
||||
Zoresvit
|
||||
|
|
|
|||
|
|
@ -4,6 +4,9 @@ Release history
|
|||
Next release
|
||||
============
|
||||
|
||||
* All settings for slugs now use ``{slug}`` and/or ``{lang}`` rather than
|
||||
``%s``. If ``%s``-style settings are encountered, Pelican will emit a warning
|
||||
and fallback to the default setting.
|
||||
* New signal: ``feed_generated``
|
||||
* Replace Fabric by Invoke and ``fabfile.py`` template by ``tasks.py``.
|
||||
* Replace ``SLUG_SUBSTITUTIONS`` (and friends) by ``SLUG_REGEX_SUBSTITUTIONS``
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ which you map the signals to your plugin logic. Let's take a simple example::
|
|||
from pelican import signals
|
||||
|
||||
def test(sender):
|
||||
print "%s initialized !!" % sender
|
||||
print("{} initialized !!".format(sender))
|
||||
|
||||
def register():
|
||||
signals.initialized.connect(test)
|
||||
|
|
|
|||
|
|
@ -879,59 +879,61 @@ the ``TAG_FEED_ATOM`` and ``TAG_FEED_RSS`` settings:
|
|||
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/{slug}.atom.xml'
|
||||
|
||||
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.
|
||||
Relative URL of the category Atom feeds, including the ``{slug}``
|
||||
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
|
||||
|
||||
The location to save the category RSS feeds, including the ``%s``
|
||||
The location to save the category RSS feeds, including the ``{slug}``
|
||||
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.
|
||||
Relative URL of the category RSS feeds, including the ``{slug}``
|
||||
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/{slug}.atom.xml'
|
||||
|
||||
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.
|
||||
Relative URL of the author Atom feeds, including the ``{slug}`` 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/{slug}.rss.xml'
|
||||
|
||||
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.
|
||||
Relative URL of the author RSS feeds, including the ``{slug}`` 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
|
||||
|
||||
The location to save the tag Atom feed, including the ``%s`` placeholder.
|
||||
[2]_
|
||||
The location to save the tag Atom feed, including the ``{slug}``
|
||||
placeholder. [2]_
|
||||
|
||||
.. data:: TAG_FEED_ATOM_URL = None
|
||||
|
||||
Relative URL of the tag Atom feed, including the ``%s`` placeholder. [2]_
|
||||
Relative URL of the tag Atom feed, including the ``{slug}`` placeholder.
|
||||
[2]_
|
||||
|
||||
.. data:: TAG_FEED_RSS = None, i.e. no RSS tag 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.
|
||||
Relative URL to output the tag RSS feed, including the ``{slug}``
|
||||
placeholder. If not set, ``TAG_FEED_RSS`` is used both for save location and
|
||||
URL.
|
||||
|
||||
.. data:: FEED_MAX_ITEMS
|
||||
|
||||
|
|
@ -946,7 +948,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``.
|
||||
|
||||
.. [2] ``%s`` is replaced by name of the category / author / tag.
|
||||
.. [2] ``{slug}`` is replaced by name of the category / author / tag.
|
||||
|
||||
|
||||
FeedBurner
|
||||
|
|
@ -1050,13 +1052,13 @@ more information.
|
|||
of one another. May be a string or a collection of strings. Set to ``None``
|
||||
or ``False`` to disable the identification of translations.
|
||||
|
||||
.. data:: TRANSLATION_FEED_ATOM = 'feeds/all-%s.atom.xml'
|
||||
.. data:: TRANSLATION_FEED_ATOM = 'feeds/all-{lang}.atom.xml'
|
||||
|
||||
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``
|
||||
Relative URL of the Atom feed for translations, including the ``{lang}``
|
||||
placeholder. [3]_ If not set, ``TRANSLATION_FEED_ATOM`` is used both for
|
||||
save location and URL.
|
||||
|
||||
|
|
@ -1066,11 +1068,11 @@ more information.
|
|||
|
||||
.. data:: TRANSLATION_FEED_RSS_URL = None
|
||||
|
||||
Relative URL of the RSS feed for translations, including the ``%s``
|
||||
Relative URL of the RSS feed for translations, including the ``{lang}``
|
||||
placeholder. [3]_ If not set, ``TRANSLATION_FEED_RSS`` is used both for save
|
||||
location and URL.
|
||||
|
||||
.. [3] %s is the language
|
||||
.. [3] {lang} is the language code
|
||||
|
||||
|
||||
Ordering content
|
||||
|
|
|
|||
|
|
@ -302,17 +302,21 @@ class ArticlesGenerator(CachingGenerator):
|
|||
"""Generate the feeds from the current context, and output files."""
|
||||
|
||||
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.get('FEED_ATOM_URL',
|
||||
self.settings['FEED_ATOM']))
|
||||
self.settings.get('FEED_ATOM_URL', self.settings['FEED_ATOM'])
|
||||
)
|
||||
|
||||
if self.settings.get('FEED_RSS'):
|
||||
writer.write_feed(self.articles, self.context,
|
||||
writer.write_feed(
|
||||
self.articles,
|
||||
self.context,
|
||||
self.settings['FEED_RSS'],
|
||||
self.settings.get('FEED_RSS_URL',
|
||||
self.settings['FEED_RSS']),
|
||||
feed_type='rss')
|
||||
self.settings.get('FEED_RSS_URL', self.settings['FEED_RSS']),
|
||||
feed_type='rss'
|
||||
)
|
||||
|
||||
if (self.settings.get('FEED_ALL_ATOM') or
|
||||
self.settings.get('FEED_ALL_RSS')):
|
||||
|
|
@ -323,80 +327,105 @@ class ArticlesGenerator(CachingGenerator):
|
|||
order_by=self.settings['ARTICLE_ORDER_BY'])
|
||||
|
||||
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.get(
|
||||
'FEED_ALL_ATOM_URL',
|
||||
self.settings['FEED_ALL_ATOM']))
|
||||
self.settings.get('FEED_ALL_ATOM_URL',
|
||||
self.settings['FEED_ALL_ATOM'])
|
||||
)
|
||||
|
||||
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.get(
|
||||
'FEED_ALL_RSS_URL',
|
||||
self.settings.get('FEED_ALL_RSS_URL',
|
||||
self.settings['FEED_ALL_RSS']),
|
||||
feed_type='rss')
|
||||
feed_type='rss'
|
||||
)
|
||||
|
||||
for cat, arts in self.categories:
|
||||
if self.settings.get('CATEGORY_FEED_ATOM'):
|
||||
writer.write_feed(arts, self.context,
|
||||
self.settings['CATEGORY_FEED_ATOM']
|
||||
% cat.slug,
|
||||
writer.write_feed(
|
||||
arts,
|
||||
self.context,
|
||||
self.settings['CATEGORY_FEED_ATOM'].format(slug=cat.slug),
|
||||
self.settings.get(
|
||||
'CATEGORY_FEED_ATOM_URL',
|
||||
self.settings['CATEGORY_FEED_ATOM'])
|
||||
% cat.slug, feed_title=cat.name)
|
||||
self.settings['CATEGORY_FEED_ATOM']).format(
|
||||
slug=cat.slug
|
||||
),
|
||||
feed_title=cat.name
|
||||
)
|
||||
|
||||
if self.settings.get('CATEGORY_FEED_RSS'):
|
||||
writer.write_feed(arts, self.context,
|
||||
self.settings['CATEGORY_FEED_RSS']
|
||||
% cat.slug,
|
||||
writer.write_feed(
|
||||
arts,
|
||||
self.context,
|
||||
self.settings['CATEGORY_FEED_RSS'].format(slug=cat.slug),
|
||||
self.settings.get(
|
||||
'CATEGORY_FEED_RSS_URL',
|
||||
self.settings['CATEGORY_FEED_RSS'])
|
||||
% cat.slug, feed_title=cat.name,
|
||||
feed_type='rss')
|
||||
self.settings['CATEGORY_FEED_RSS']).format(
|
||||
slug=cat.slug
|
||||
),
|
||||
feed_title=cat.name,
|
||||
feed_type='rss'
|
||||
)
|
||||
|
||||
for auth, arts in self.authors:
|
||||
if self.settings.get('AUTHOR_FEED_ATOM'):
|
||||
writer.write_feed(arts, self.context,
|
||||
self.settings['AUTHOR_FEED_ATOM']
|
||||
% auth.slug,
|
||||
writer.write_feed(
|
||||
arts,
|
||||
self.context,
|
||||
self.settings['AUTHOR_FEED_ATOM'].format(slug=auth.slug),
|
||||
self.settings.get(
|
||||
'AUTHOR_FEED_ATOM_URL',
|
||||
self.settings['AUTHOR_FEED_ATOM'])
|
||||
% auth.slug, feed_title=auth.name)
|
||||
self.settings['AUTHOR_FEED_ATOM']
|
||||
).format(slug=auth.slug),
|
||||
feed_title=auth.name
|
||||
)
|
||||
|
||||
if self.settings.get('AUTHOR_FEED_RSS'):
|
||||
writer.write_feed(arts, self.context,
|
||||
self.settings['AUTHOR_FEED_RSS']
|
||||
% auth.slug,
|
||||
writer.write_feed(
|
||||
arts,
|
||||
self.context,
|
||||
self.settings['AUTHOR_FEED_RSS'].format(slug=auth.slug),
|
||||
self.settings.get(
|
||||
'AUTHOR_FEED_RSS_URL',
|
||||
self.settings['AUTHOR_FEED_RSS'])
|
||||
% auth.slug, feed_title=auth.name,
|
||||
feed_type='rss')
|
||||
self.settings['AUTHOR_FEED_RSS']
|
||||
).format(slug=auth.slug),
|
||||
feed_title=auth.name,
|
||||
feed_type='rss'
|
||||
)
|
||||
|
||||
if (self.settings.get('TAG_FEED_ATOM') or
|
||||
self.settings.get('TAG_FEED_RSS')):
|
||||
for tag, arts in self.tags.items():
|
||||
if self.settings.get('TAG_FEED_ATOM'):
|
||||
writer.write_feed(arts, self.context,
|
||||
self.settings['TAG_FEED_ATOM']
|
||||
% tag.slug,
|
||||
writer.write_feed(
|
||||
arts,
|
||||
self.context,
|
||||
self.settings['TAG_FEED_ATOM'].format(slug=tag.slug),
|
||||
self.settings.get(
|
||||
'TAG_FEED_ATOM_URL',
|
||||
self.settings['TAG_FEED_ATOM'])
|
||||
% tag.slug, feed_title=tag.name)
|
||||
self.settings['TAG_FEED_ATOM']
|
||||
).format(slug=tag.slug),
|
||||
feed_title=tag.name
|
||||
)
|
||||
|
||||
if self.settings.get('TAG_FEED_RSS'):
|
||||
writer.write_feed(arts, self.context,
|
||||
self.settings['TAG_FEED_RSS'] % tag.slug,
|
||||
writer.write_feed(
|
||||
arts,
|
||||
self.context,
|
||||
self.settings['TAG_FEED_RSS'].format(slug=tag.slug),
|
||||
self.settings.get(
|
||||
'TAG_FEED_RSS_URL',
|
||||
self.settings['TAG_FEED_RSS'])
|
||||
% tag.slug, feed_title=tag.name,
|
||||
feed_type='rss')
|
||||
self.settings['TAG_FEED_RSS']
|
||||
).format(slug=tag.slug),
|
||||
feed_title=tag.name,
|
||||
feed_type='rss'
|
||||
)
|
||||
|
||||
if (self.settings.get('TRANSLATION_FEED_ATOM') or
|
||||
self.settings.get('TRANSLATION_FEED_RSS')):
|
||||
|
|
@ -409,19 +438,27 @@ class ArticlesGenerator(CachingGenerator):
|
|||
items, order_by=self.settings['ARTICLE_ORDER_BY'])
|
||||
if self.settings.get('TRANSLATION_FEED_ATOM'):
|
||||
writer.write_feed(
|
||||
items, self.context,
|
||||
self.settings['TRANSLATION_FEED_ATOM'] % lang,
|
||||
items,
|
||||
self.context,
|
||||
self.settings['TRANSLATION_FEED_ATOM']
|
||||
.format(lang=lang),
|
||||
self.settings.get(
|
||||
'TRANSLATION_FEED_ATOM_URL',
|
||||
self.settings['TRANSLATION_FEED_ATOM']) % lang)
|
||||
self.settings['TRANSLATION_FEED_ATOM']
|
||||
).format(lang=lang),
|
||||
)
|
||||
if self.settings.get('TRANSLATION_FEED_RSS'):
|
||||
writer.write_feed(
|
||||
items, self.context,
|
||||
self.settings['TRANSLATION_FEED_RSS'] % lang,
|
||||
items,
|
||||
self.context,
|
||||
self.settings['TRANSLATION_FEED_RSS']
|
||||
.format(lang=lang),
|
||||
self.settings.get(
|
||||
'TRANSLATION_FEED_RSS_URL',
|
||||
self.settings['TRANSLATION_FEED_RSS']) % lang,
|
||||
feed_type='rss')
|
||||
self.settings['TRANSLATION_FEED_RSS']
|
||||
).format(lang=lang),
|
||||
feed_type='rss'
|
||||
)
|
||||
|
||||
def generate_articles(self, write):
|
||||
"""Generate the articles."""
|
||||
|
|
|
|||
|
|
@ -45,10 +45,10 @@ DEFAULT_CONFIG = {
|
|||
'THEME_STATIC_DIR': 'theme',
|
||||
'THEME_STATIC_PATHS': ['static', ],
|
||||
'FEED_ALL_ATOM': posix_join('feeds', 'all.atom.xml'),
|
||||
'CATEGORY_FEED_ATOM': posix_join('feeds', '%s.atom.xml'),
|
||||
'AUTHOR_FEED_ATOM': posix_join('feeds', '%s.atom.xml'),
|
||||
'AUTHOR_FEED_RSS': posix_join('feeds', '%s.rss.xml'),
|
||||
'TRANSLATION_FEED_ATOM': posix_join('feeds', 'all-%s.atom.xml'),
|
||||
'CATEGORY_FEED_ATOM': posix_join('feeds', '{slug}.atom.xml'),
|
||||
'AUTHOR_FEED_ATOM': posix_join('feeds', '{slug}.atom.xml'),
|
||||
'AUTHOR_FEED_RSS': posix_join('feeds', '{slug}.rss.xml'),
|
||||
'TRANSLATION_FEED_ATOM': posix_join('feeds', 'all-{lang}.atom.xml'),
|
||||
'FEED_MAX_ITEMS': '',
|
||||
'RSS_FEED_SUMMARY_ONLY': True,
|
||||
'SITEURL': '',
|
||||
|
|
@ -385,6 +385,26 @@ def handle_deprecated_settings(settings):
|
|||
settings[f + '_REGEX_SUBSTITUTIONS'] = regex_subs
|
||||
settings.pop(f + '_SUBSTITUTIONS', None)
|
||||
|
||||
# `%s` -> '{slug}` or `{lang}` in FEED settings
|
||||
for key in ['TRANSLATION_FEED_ATOM',
|
||||
'TRANSLATION_FEED_RSS'
|
||||
]:
|
||||
if key in settings and '%s' in settings[key]:
|
||||
logger.warning('%%s usage in %s is deprecated, use {lang} '
|
||||
'instead. Falling back to default.', key)
|
||||
settings[key] = DEFAULT_CONFIG[key]
|
||||
for key in ['AUTHOR_FEED_ATOM',
|
||||
'AUTHOR_FEED_RSS',
|
||||
'CATEGORY_FEED_ATOM',
|
||||
'CATEGORY_FEED_RSS',
|
||||
'TAG_FEED_ATOM',
|
||||
'TAG_FEED_RSS',
|
||||
]:
|
||||
if key in settings and '%s' in settings[key]:
|
||||
logger.warning('%%s usage in %s is deprecated, use {slug} '
|
||||
'instead. Falling back to default.', key)
|
||||
settings[key] = DEFAULT_CONFIG[key]
|
||||
|
||||
return settings
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ REVERSE_CATEGORY_ORDER = True
|
|||
DEFAULT_PAGINATION = 2
|
||||
|
||||
FEED_RSS = 'feeds/all.rss.xml'
|
||||
CATEGORY_FEED_RSS = 'feeds/%s.rss.xml'
|
||||
CATEGORY_FEED_RSS = 'feeds/{slug}.rss.xml'
|
||||
|
||||
LINKS = (('Biologeek', 'http://biologeek.org'),
|
||||
('Filyb', "http://filyb.info/"),
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ SITEURL = '{{siteurl}}'
|
|||
RELATIVE_URLS = False
|
||||
|
||||
FEED_ALL_ATOM = 'feeds/all.atom.xml'
|
||||
CATEGORY_FEED_ATOM = 'feeds/%s.atom.xml'
|
||||
CATEGORY_FEED_ATOM = 'feeds/{slug}.atom.xml'
|
||||
|
||||
DELETE_OUTPUT_DIRECTORY = True
|
||||
|
||||
|
|
|
|||
2
samples/pelican.conf.py
vendored
2
samples/pelican.conf.py
vendored
|
|
@ -18,7 +18,7 @@ DEFAULT_PAGINATION = 4
|
|||
DEFAULT_DATE = (2012, 3, 2, 14, 1, 1)
|
||||
|
||||
FEED_ALL_RSS = 'feeds/all.rss.xml'
|
||||
CATEGORY_FEED_RSS = 'feeds/%s.rss.xml'
|
||||
CATEGORY_FEED_RSS = 'feeds/{slug}.rss.xml'
|
||||
|
||||
LINKS = (('Biologeek', 'http://biologeek.org'),
|
||||
('Filyb', "http://filyb.info/"),
|
||||
|
|
|
|||
2
samples/pelican.conf_FR.py
vendored
2
samples/pelican.conf_FR.py
vendored
|
|
@ -22,7 +22,7 @@ ARTICLE_URL = 'posts/{date:%Y}/{date:%B}/{date:%d}/{slug}/'
|
|||
ARTICLE_SAVE_AS = ARTICLE_URL + 'index.html'
|
||||
|
||||
FEED_ALL_RSS = 'feeds/all.rss.xml'
|
||||
CATEGORY_FEED_RSS = 'feeds/%s.rss.xml'
|
||||
CATEGORY_FEED_RSS = 'feeds/{slug}.rss.xml'
|
||||
|
||||
LINKS = (('Biologeek', 'http://biologeek.org'),
|
||||
('Filyb', "http://filyb.info/"),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue