diff options
author | MinchinWeb <w_minchin@hotmail.com> | 2018-11-03 09:12:20 -0600 |
---|---|---|
committer | Justin Mayer <entroP@gmail.com> | 2018-11-03 16:12:20 +0100 |
commit | 3a0add4b6e66fe08e9f5710f98235491c09e4f81 (patch) | |
tree | 393369e2d7f130595b59a2ddb6433f98d21de62f | |
parent | 682b0b6711369637fefd96eb2da95cbd5bfaa85e (diff) | |
download | pelican-3a0add4b6e66fe08e9f5710f98235491c09e4f81.tar.gz |
Convert FEED settings from `%s` to `{slug}` redux (#2432)
* Convert FEED settings from `%s` to `{slug}` redux
Closes #2106, Closes #2383
-rw-r--r-- | THANKS | 1 | ||||
-rw-r--r-- | docs/changelog.rst | 3 | ||||
-rw-r--r-- | docs/plugins.rst | 2 | ||||
-rw-r--r-- | docs/settings.rst | 48 | ||||
-rw-r--r-- | pelican/generators.py | 177 | ||||
-rw-r--r-- | pelican/settings.py | 28 | ||||
-rw-r--r-- | pelican/tests/default_conf.py | 2 | ||||
-rwxr-xr-x | pelican/tools/templates/publishconf.py.jinja2 | 2 | ||||
-rwxr-xr-x | samples/pelican.conf.py | 2 | ||||
-rw-r--r-- | samples/pelican.conf_FR.py | 2 |
10 files changed, 165 insertions, 102 deletions
@@ -155,6 +155,7 @@ Tshepang Lekhonkhobe Valentin-Costel Hăloiu Vlad Niculae William Light +William Minchin Wladislaw Merezhko W. Trevor King Zoresvit diff --git a/docs/changelog.rst b/docs/changelog.rst index 858a6e1b..3d3fddc8 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -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`` diff --git a/docs/plugins.rst b/docs/plugins.rst index 4e0ec6d1..18c18364 100644 --- a/docs/plugins.rst +++ b/docs/plugins.rst @@ -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) diff --git a/docs/settings.rst b/docs/settings.rst index 28b68980..7d5fa324 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -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 diff --git a/pelican/generators.py b/pelican/generators.py index 90e4c8a5..0e772a62 100644 --- a/pelican/generators.py +++ b/pelican/generators.py @@ -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, - self.settings['FEED_ATOM'], - self.settings.get('FEED_ATOM_URL', - self.settings['FEED_ATOM'])) + writer.write_feed( + self.articles, + self.context, + 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, - self.settings['FEED_RSS'], - self.settings.get('FEED_RSS_URL', - self.settings['FEED_RSS']), - feed_type='rss') + writer.write_feed( + self.articles, + self.context, + 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 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, - self.settings['FEED_ALL_ATOM'], - self.settings.get( - 'FEED_ALL_ATOM_URL', - self.settings['FEED_ALL_ATOM'])) + writer.write_feed( + all_articles, + self.context, + 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, - self.settings['FEED_ALL_RSS'], - self.settings.get( - 'FEED_ALL_RSS_URL', + writer.write_feed( + all_articles, + self.context, + 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: if self.settings.get('CATEGORY_FEED_ATOM'): - writer.write_feed(arts, self.context, - 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) + 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']).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, - self.settings.get( - 'CATEGORY_FEED_RSS_URL', - self.settings['CATEGORY_FEED_RSS']) - % cat.slug, feed_title=cat.name, - feed_type='rss') + 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']).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, - self.settings.get( - 'AUTHOR_FEED_ATOM_URL', - self.settings['AUTHOR_FEED_ATOM']) - % auth.slug, feed_title=auth.name) + 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'] + ).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, - self.settings.get( - 'AUTHOR_FEED_RSS_URL', - self.settings['AUTHOR_FEED_RSS']) - % auth.slug, feed_title=auth.name, - feed_type='rss') + 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'] + ).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, - self.settings.get( - 'TAG_FEED_ATOM_URL', - self.settings['TAG_FEED_ATOM']) - % tag.slug, feed_title=tag.name) + 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'] + ).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, - self.settings.get( - 'TAG_FEED_RSS_URL', - self.settings['TAG_FEED_RSS']) - % tag.slug, feed_title=tag.name, - feed_type='rss') + 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'] + ).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.""" diff --git a/pelican/settings.py b/pelican/settings.py index 0bf4284a..6907051c 100644 --- a/pelican/settings.py +++ b/pelican/settings.py @@ -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 diff --git a/pelican/tests/default_conf.py b/pelican/tests/default_conf.py index 77c2b947..a567dc10 100644 --- a/pelican/tests/default_conf.py +++ b/pelican/tests/default_conf.py @@ -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/"), diff --git a/pelican/tools/templates/publishconf.py.jinja2 b/pelican/tools/templates/publishconf.py.jinja2 index 4b9a7cba..913de7f1 100755 --- a/pelican/tools/templates/publishconf.py.jinja2 +++ b/pelican/tools/templates/publishconf.py.jinja2 @@ -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 diff --git a/samples/pelican.conf.py b/samples/pelican.conf.py index da5c5dc5..0f67ee83 100755 --- a/samples/pelican.conf.py +++ b/samples/pelican.conf.py @@ -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/"), diff --git a/samples/pelican.conf_FR.py b/samples/pelican.conf_FR.py index 54b348c4..b1571e8a 100644 --- a/samples/pelican.conf_FR.py +++ b/samples/pelican.conf_FR.py @@ -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/"), |