chiark / gitweb /
theme: support for archived articles.
authorVladimír Vondruš <mosra@centrum.cz>
Tue, 16 Jan 2018 17:03:45 +0000 (18:03 +0100)
committerVladimír Vondruš <mosra@centrum.cz>
Tue, 16 Jan 2018 21:45:39 +0000 (22:45 +0100)
doc/pelican/theme.rst
pelican-theme/templates/article.html
pelican-theme/templates/article_footer.html
pelican-theme/test/blog_archived_article/article-jumbo.html [new file with mode: 0644]
pelican-theme/test/blog_archived_article/article-jumbo.rst [new file with mode: 0644]
pelican-theme/test/blog_archived_article/article.html [new file with mode: 0644]
pelican-theme/test/blog_archived_article/article.rst [new file with mode: 0644]
pelican-theme/test/test_blog.py

index c277cef405d295470c54434c6f684acdee8c5486..0e43d2828d5f2c8801bc4ca5ae84bb7090f81a2e 100644 (file)
@@ -612,6 +612,26 @@ invert text color on cover, add a :rst:`:class:` field containing the
     `a normal article <{filename}/examples/article.rst>`_ and a
     `jumbo article <{filename}/examples/jumbo-article.rst>`_.
 
+`Archived articles`_
+--------------------
+
+It's possible to mark articles and archived by setting the :rst:`:archived:`
+field to :py:`True`. In addition to that, you can display an arbitrary
+formatted block on the article page on top of article contents right below the
+summary. The content of the block is controlled by the
+:py:`M_ARCHIVED_ARTICLE_BADGE` setting, containinig
+:abbr:`reST <reStructuredText>`-formatted markup. The ``{year}`` placeholder,
+if present, is replaced with the article year. If the setting is not present,
+no block is rendered at all. Example setting:
+
+.. code:: py
+
+    M_ARCHIVED_ARTICLE_BADGE = """
+    .. container:: m-note m-warning
+
+        This article is from {year}. **It's old.** Deal with it.
+    """
+
 `(Social) meta tags for articles`_
 ----------------------------------
 
index 92ee30fe87a805203b2a6cb64fc5bf37210ed038..79a9f515ebfa37db790ba811ec24b1b81ffba595 100644 (file)
@@ -87,6 +87,9 @@
     <div class="m-container m-container-inflatable">
       <div class="m-row">
         <div class="m-col-m-10 m-push-m-1 m-nopady">
+          {% if article.archived == 'True' and M_ARCHIVED_ARTICLE_BADGE %}
+          {{ M_ARCHIVED_ARTICLE_BADGE|render_rst|replace('{year}', article.date.year)|indent(8) }}
+          {% endif %}
 <!-- content -->
 {{ article.content|trim }}
 <!-- /content -->
       {% macro header() %}{% include "article_header.html" %}{% endmacro %}
       {{ header()|indent(6) }}
       <div class="m-clearfix-l"></div>
+      {% if article.archived == 'True' and M_ARCHIVED_ARTICLE_BADGE %}
+      {{ M_ARCHIVED_ARTICLE_BADGE|render_rst|replace('{year}', article.date.year)|indent(6) }}
+      {% endif %}
       {% if article.content %}
 <!-- content -->
 {{ article.content|trim }}
index 5230fa88b10f8ae4458ed702d975c5c1a849af2c..98c1020765ce0617fe672834d172044e29b02fa5 100644 (file)
@@ -1 +1 @@
-<p>Posted{% if article.authors %} by {% for author in article.authors %}<a href="{{ author.url|format_siteurl|e }}">{{ author|e }}</a>{% endfor %}{% endif %} on <time datetime="{{ article.date.isoformat() }}">{{ article.locale_date }}</time> in <a href="{{ article.category.url|format_siteurl|e }}">{{ article.category|e }}</a>.{% if article.modified %} <span class="m-label m-success">updated <time datetime="{{ article.modified.isoformat() }}">{{ article.locale_modified }}</time></span>{% endif %}{% if article.tags %} Tags: {% for tag in article.tags %}<a href="{{ tag.url|format_siteurl|e }}">{{ tag|e }}</a>{% if not loop.last %}, {% endif %}{% endfor %}.{% endif %}</p>
+<p>Posted{% if article.authors %} by {% for author in article.authors %}<a href="{{ author.url|format_siteurl|e }}">{{ author|e }}</a>{% endfor %}{% endif %} on <time datetime="{{ article.date.isoformat() }}">{{ article.locale_date }}</time> in <a href="{{ article.category.url|format_siteurl|e }}">{{ article.category|e }}</a>.{% if article.modified %} <span class="m-label m-success">updated <time datetime="{{ article.modified.isoformat() }}">{{ article.locale_modified }}</time></span>{% endif %}{% if article.archived == 'True' %} <span class="m-label m-warning">archived</span>{% endif %}{% if article.tags %} Tags: {% for tag in article.tags %}<a href="{{ tag.url|format_siteurl|e }}">{{ tag|e }}</a>{% if not loop.last %}, {% endif %}{% endfor %}.{% endif %}</p>
diff --git a/pelican-theme/test/blog_archived_article/article-jumbo.html b/pelican-theme/test/blog_archived_article/article-jumbo.html
new file mode 100644 (file)
index 0000000..ff72c3d
--- /dev/null
@@ -0,0 +1,75 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+  <meta charset="UTF-8" />
+  <title>A jumbo article | 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 rel="canonical" href="article-jumbo.html" />
+  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+</head>
+<body>
+<header><nav id="navigation" class="m-navbar-cover">
+  <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>
+  <article id="m-jumbo">
+    <header>
+      <div id="m-jumbo-image" style="background-image: url('image.jpg');">
+        <div id="m-jumbo-cover">
+          <div class="m-container">
+            <div class="m-row">
+              <div class="m-col-t-12 m-col-s-10 m-push-s-1 m-text-left">Jan 16, 1982</div>
+            </div>
+            <div class="m-row">
+              <div class="m-col-t-12 m-col-s-10 m-push-s-1 m-col-m-8 m-push-m-2">
+                <h1><a href="article-jumbo.html" rel="bookmark" title="Permalink to A jumbo article">A jumbo article</a></h1>
+              </div>
+            </div>
+          </div>
+        </div>
+      </div>
+      <div class="m-container">
+        <div class="m-row">
+          <div class="m-col-m-10 m-push-m-1 m-nopady">
+            <p>Article content.</p>
+          </div>
+        </div>
+      </div>
+    </header>
+    <div class="m-container m-container-inflatable">
+      <div class="m-row">
+        <div class="m-col-m-10 m-push-m-1 m-nopady">
+          <div class="m-note m-warning">
+        This article is from 1982. <strong>It's old.</strong> Deal with it.</div>
+<!-- content -->
+<p>Article content.</p>
+<!-- /content -->
+        </div>
+      </div>
+    </div>
+    <footer class="m-container">
+      <div class="m-row">
+        <div class="m-col-m-10 m-push-m-1 m-nopadb">
+          <p>Posted on <time datetime="1982-01-16T00:00:00+00:00">Jan 16, 1982</time> in <a href="category-misc.html">misc</a>. <span class="m-label m-warning">archived</span></p>
+        </div>
+      </div>
+    </footer>
+  </article>
+  <nav class="m-navpanel m-container">
+    <div class="m-row">
+      <div class="m-col-s-4 m-col-l-2 m-push-s-4 m-push-l-5">
+        <h3>Categories</h3>
+        <ol class="m-block-bar-s">
+          <li><a href="category-misc.html">misc</a></li>
+        </ol>
+      </div>
+    </div>
+  </nav>
+</main>
+</body>
+</html>
diff --git a/pelican-theme/test/blog_archived_article/article-jumbo.rst b/pelican-theme/test/blog_archived_article/article-jumbo.rst
new file mode 100644 (file)
index 0000000..39de962
--- /dev/null
@@ -0,0 +1,8 @@
+A jumbo article
+###############
+
+:date: 1982-01-16
+:cover: image.jpg
+:archived: True
+
+Article content.
diff --git a/pelican-theme/test/blog_archived_article/article.html b/pelican-theme/test/blog_archived_article/article.html
new file mode 100644 (file)
index 0000000..23a5f99
--- /dev/null
@@ -0,0 +1,52 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+  <meta charset="UTF-8" />
+  <title>An article | 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 rel="canonical" href="article.html" />
+  <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">
+    <article class="m-col-m-10 m-nopadb">
+      <header>
+        <h1><a href="article.html" rel="bookmark" title="Permalink to An article">
+          <time class="m-date" datetime="1982-01-16T00:00:00+00:00">
+            Jan <span class="m-date-day">16</span> 1982
+          </time>
+          An article
+        </a></h1>
+        <p>Article content.</p>
+      </header>
+      <div class="m-clearfix-l"></div>
+      <div class="m-note m-warning">
+      This article is from 1982. <strong>It's old.</strong> Deal with it.</div>
+<!-- content -->
+<p>Article content.</p>
+<!-- /content -->
+      <footer>
+        <p>Posted on <time datetime="1982-01-16T00:00:00+00:00">Jan 16, 1982</time> in <a href="category-misc.html">misc</a>. <span class="m-label m-warning">archived</span></p>
+      </footer>
+    </article>
+    <nav class="m-navpanel m-col-m-2">
+      <h3>Categories</h3>
+      <ol class="m-block-bar-m">
+        <li><a href="category-misc.html">misc</a></li>
+      </ol>
+    </nav>
+  </div>
+</div>
+</main>
+</body>
+</html>
diff --git a/pelican-theme/test/blog_archived_article/article.rst b/pelican-theme/test/blog_archived_article/article.rst
new file mode 100644 (file)
index 0000000..a91825e
--- /dev/null
@@ -0,0 +1,7 @@
+An article
+##########
+
+:date: 1982-01-16
+:archived: True
+
+Article content.
index 9c01e7630e9f19f5a5b41e218674e52adbfdc3b7..c8270a597b1b56daa5440e76d3cba400345870ee 100644 (file)
@@ -494,3 +494,19 @@ class GlobalSocialMeta(BlogTestCase):
         self.assertEqual(*self.actual_expected_contents('category-a-category.html'))
         self.assertEqual(*self.actual_expected_contents('author-the-author.html'))
         self.assertEqual(*self.actual_expected_contents('tag-a-tag.html'))
+
+class ArchivedArticle(BlogTestCase):
+    def __init__(self, *args, **kwargs):
+        super().__init__(__file__, 'archived_article', *args, **kwargs)
+
+    def test(self):
+        self.run_pelican({
+            'M_ARCHIVED_ARTICLE_BADGE': """
+.. container:: m-note m-warning
+
+    This article is from {year}. **It's old.** Deal with it.
+"""
+        })
+
+        self.assertEqual(*self.actual_expected_contents('article.html'))
+        self.assertEqual(*self.actual_expected_contents('article-jumbo.html'))