chiark / gitweb /
theme: properly fallback to FEED_ATOM if FEED_ATOM_URL is not set.
authorVladimír Vondruš <mosra@centrum.cz>
Thu, 13 Sep 2018 15:05:05 +0000 (17:05 +0200)
committerVladimír Vondruš <mosra@centrum.cz>
Thu, 13 Sep 2018 15:14:10 +0000 (17:14 +0200)
pelican-plugins/m/test/__init__.py
pelican-theme/templates/base.html
pelican-theme/test/__init__.py
pelican-theme/test/blog_feeds/article.rst [new file with mode: 0644]
pelican-theme/test/blog_feeds/category-a-category.html [new file with mode: 0644]
pelican-theme/test/blog_feeds/index.html [new file with mode: 0644]
pelican-theme/test/blog_feeds_no_url/article.rst [new file with mode: 0644]
pelican-theme/test/test_blog.py

index 45c77de1ebb281076e940e7e14fdcb9142fa02fc..8050b498bd5d8f883764ce3d47f0088a795b70ec 100644 (file)
@@ -55,7 +55,9 @@ class PluginTestCase(unittest.TestCase):
             'PAGE_URL': '{slug}.html',
             'PAGE_EXCLUDES': ['output'],
             'ARTICLE_PATHS': ['articles'], # does not exist
-            'FEED_ALL_ATOM': None, # Don't render feeds, we're not testing them *ever*
+            # Don't render feeds, we don't want to test them all the time
+            'FEED_ALL_ATOM': None,
+            'CATEGORY_FEED_ATOM': None,
             'THEME': '../pelican-theme',
             'PLUGIN_PATHS': ['.'],
             'THEME_STATIC_DIR': 'static',
index aed2a29cb5578753ae87f917722b3fff1780537a..9c9930d778d27b99bd4d41d4eb5825fbc5c74971 100644 (file)
   {% endblock head_links %}
   {% if FEED_ALL_ATOM_URL %}
   <link href="{{ FEED_ALL_ATOM_URL|format_siteurl|e }}" type="application/atom+xml" rel="alternate" title="{{ SITENAME|e }}" />
+  {% elif FEED_ALL_ATOM %}
+  <link href="{{ FEED_ALL_ATOM|format_siteurl|e }}" type="application/atom+xml" rel="alternate" title="{{ SITENAME|e }}" />
   {% endif %}
-  {% if CATEGORY_FEED_ATOM_URL and category %}
+  {% if category %}
+  {% if CATEGORY_FEED_ATOM_URL %}
   <link href="{{ CATEGORY_FEED_ATOM_URL|format(category.slug)|format_siteurl }}" type="application/atom+xml" rel="alternate" title="{{ SITENAME|e }} | {{ category|e }}" />
+  {% elif CATEGORY_FEED_ATOM %}
+  <link href="{{ CATEGORY_FEED_ATOM|format(category.slug)|format_siteurl }}" type="application/atom+xml" rel="alternate" title="{{ SITENAME|e }} | {{ category|e }}" />
+  {% endif %}
   {% endif %}
   <meta name="viewport" content="width=device-width, initial-scale=1.0" />
   {% if M_THEME_COLOR %}
index 935e4285fb0f09dcbcc65c4a87140c1be06bf7b4..ddd0ce9c7191eb8eb233d5860f41e829d165817b 100644 (file)
@@ -52,7 +52,9 @@ class MinimalTestCase(unittest.TestCase):
             'OUTPUT_PATH': os.path.join(self.path, 'output'),
             'PAGE_EXCLUDES': [os.path.join(self.path, 'output')],
             'ARTICLE_EXCLUDES': [os.path.join(self.path, 'output')],
-            'FEED_ALL_ATOM': None, # Don't render feeds, we're not testing them *ever*
+            # Don't render feeds, we don't want to test them all the time
+            'FEED_ALL_ATOM': None,
+            'CATEGORY_FEED_ATOM': None
         }
         implicit_settings.update(settings)
         settings = read_settings(path=None, override=implicit_settings)
diff --git a/pelican-theme/test/blog_feeds/article.rst b/pelican-theme/test/blog_feeds/article.rst
new file mode 100644 (file)
index 0000000..594c9b7
--- /dev/null
@@ -0,0 +1,5 @@
+An article
+##########
+
+:date: 2018-09-13
+:category: A Category
diff --git a/pelican-theme/test/blog_feeds/category-a-category.html b/pelican-theme/test/blog_feeds/category-a-category.html
new file mode 100644 (file)
index 0000000..1f82b2c
--- /dev/null
@@ -0,0 +1,52 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+  <meta charset="UTF-8" />
+  <title>A Category | A Pelican Blog</title>
+  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,400i,600,600i" />
+  <link rel="stylesheet" href="static/m-dark.css" />
+  <link href="feeds/atom.xml" type="application/atom+xml" rel="alternate" title="A Pelican Blog" />
+  <link href="feeds/a-category.atom.xml" type="application/atom+xml" rel="alternate" title="A Pelican Blog | A Category" />
+  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+</head>
+<body>
+<header><nav id="navigation">
+  <div class="m-container">
+    <div class="m-row">
+      <a href="./" id="m-navbar-brand" class="m-col-t-9 m-col-m-none m-left-m">A Pelican Blog</a>
+    </div>
+  </div>
+</nav></header>
+<main>
+<div class="m-container">
+  <div class="m-row">
+    <div class="m-col-m-10">
+      <div class="m-info m-note">
+        Showing only posts in <em>A Category</em>. <a href="./">Show all posts.</a>
+      </div>
+      <article>
+        <header>
+          <h1><a href="article.html" rel="bookmark" title="Permalink to An article">
+            <time class="m-date" datetime="2018-09-13T00:00:00+00:00">
+              Sep <span class="m-date-day">13</span> 2018
+            </time>
+            An article
+          </a></h1>
+        </header>
+        <footer>
+          <p>Posted on <time datetime="2018-09-13T00:00:00+00:00">Sep 13, 2018</time> in <a href="category-a-category.html">A Category</a>.</p>
+        </footer>
+        <div class="m-clearfix-l"></div>
+      </article>
+    </div>
+    <nav class="m-navpanel m-col-m-2">
+      <h3>Categories</h3>
+      <ol class="m-block-bar-m">
+        <li><a href="category-a-category.html">A Category</a></li>
+      </ol>
+    </nav>
+  </div>
+</div>
+</main>
+</body>
+</html>
diff --git a/pelican-theme/test/blog_feeds/index.html b/pelican-theme/test/blog_feeds/index.html
new file mode 100644 (file)
index 0000000..63ef57f
--- /dev/null
@@ -0,0 +1,48 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+  <meta charset="UTF-8" />
+  <title>A Pelican Blog</title>
+  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,400i,600,600i" />
+  <link rel="stylesheet" href="static/m-dark.css" />
+  <link href="feeds/atom.xml" type="application/atom+xml" rel="alternate" title="A Pelican Blog" />
+  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+</head>
+<body>
+<header><nav id="navigation">
+  <div class="m-container">
+    <div class="m-row">
+      <a href="./" id="m-navbar-brand" class="m-col-t-9 m-col-m-none m-left-m">A Pelican Blog</a>
+    </div>
+  </div>
+</nav></header>
+<main>
+<div class="m-container">
+  <div class="m-row">
+    <div class="m-col-m-10">
+      <article>
+        <header>
+          <h1><a href="article.html" rel="bookmark" title="Permalink to An article">
+            <time class="m-date" datetime="2018-09-13T00:00:00+00:00">
+              Sep <span class="m-date-day">13</span> 2018
+            </time>
+            An article
+          </a></h1>
+        </header>
+        <footer>
+          <p>Posted on <time datetime="2018-09-13T00:00:00+00:00">Sep 13, 2018</time> in <a href="category-a-category.html">A Category</a>.</p>
+        </footer>
+        <div class="m-clearfix-l"></div>
+      </article>
+    </div>
+    <nav class="m-navpanel m-col-m-2">
+      <h3>Categories</h3>
+      <ol class="m-block-bar-m">
+        <li><a href="category-a-category.html">A Category</a></li>
+      </ol>
+    </nav>
+  </div>
+</div>
+</main>
+</body>
+</html>
diff --git a/pelican-theme/test/blog_feeds_no_url/article.rst b/pelican-theme/test/blog_feeds_no_url/article.rst
new file mode 100644 (file)
index 0000000..594c9b7
--- /dev/null
@@ -0,0 +1,5 @@
+An article
+##########
+
+:date: 2018-09-13
+:category: A Category
index a0f74f9e74c502f7e2211810917b7bfe13af4de5..907329d0de882ef16f28e2d855f6ce6c51e50f22 100644 (file)
@@ -550,3 +550,35 @@ class Draft(BlogTestCase):
 
         self.assertEqual(*self.actual_expected_contents('article.html'))
         self.assertEqual(*self.actual_expected_contents('article-jumbo.html'))
+
+class Feeds(BlogTestCase):
+    def __init__(self, *args, **kwargs):
+        super().__init__(__file__, 'feeds', *args, **kwargs)
+
+    def test(self):
+        self.run_pelican({
+            'M_DISABLE_SOCIAL_META_TAGS': True,
+            'FEED_ALL_ATOM': 'atom.xml',
+            'FEED_ALL_ATOM_URL': 'feeds/atom.xml',
+            'CATEGORY_FEED_ATOM': '%s.atom.xml',
+            'CATEGORY_FEED_ATOM_URL': 'feeds/%s.atom.xml',
+        })
+
+        # There should be just the first column
+        self.assertEqual(*self.actual_expected_contents('index.html'))
+        self.assertEqual(*self.actual_expected_contents('category-a-category.html'))
+
+class FeedsNoUrl(BlogTestCase):
+    def __init__(self, *args, **kwargs):
+        super().__init__(__file__, 'feeds_no_url', *args, **kwargs)
+
+    def test(self):
+        self.run_pelican({
+            'M_DISABLE_SOCIAL_META_TAGS': True,
+            'FEED_ALL_ATOM': 'feeds/atom.xml',
+            'CATEGORY_FEED_ATOM': 'feeds/%s.atom.xml',
+        })
+
+        # The feed URLs should be the same as above
+        self.assertEqual(*self.actual_expected_contents('index.html', '../blog_feeds/index.html'))
+        self.assertEqual(*self.actual_expected_contents('category-a-category.html', '../blog_feeds/category-a-category.html'))