From 5e6bd5be44fa06e00eb1f349d71045c95d45d21c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 16 Jan 2018 18:03:45 +0100 Subject: [PATCH] theme: support for archived articles. --- doc/pelican/theme.rst | 20 +++++ pelican-theme/templates/article.html | 6 ++ pelican-theme/templates/article_footer.html | 2 +- .../blog_archived_article/article-jumbo.html | 75 +++++++++++++++++++ .../blog_archived_article/article-jumbo.rst | 8 ++ .../test/blog_archived_article/article.html | 52 +++++++++++++ .../test/blog_archived_article/article.rst | 7 ++ pelican-theme/test/test_blog.py | 16 ++++ 8 files changed, 185 insertions(+), 1 deletion(-) create mode 100644 pelican-theme/test/blog_archived_article/article-jumbo.html create mode 100644 pelican-theme/test/blog_archived_article/article-jumbo.rst create mode 100644 pelican-theme/test/blog_archived_article/article.html create mode 100644 pelican-theme/test/blog_archived_article/article.rst diff --git a/doc/pelican/theme.rst b/doc/pelican/theme.rst index c277cef4..0e43d282 100644 --- a/doc/pelican/theme.rst +++ b/doc/pelican/theme.rst @@ -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 `-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`_ ---------------------------------- diff --git a/pelican-theme/templates/article.html b/pelican-theme/templates/article.html index 92ee30fe..79a9f515 100644 --- a/pelican-theme/templates/article.html +++ b/pelican-theme/templates/article.html @@ -87,6 +87,9 @@
+ {% if article.archived == 'True' and M_ARCHIVED_ARTICLE_BADGE %} + {{ M_ARCHIVED_ARTICLE_BADGE|render_rst|replace('{year}', article.date.year)|indent(8) }} + {% endif %} {{ article.content|trim }} @@ -111,6 +114,9 @@ {% macro header() %}{% include "article_header.html" %}{% endmacro %} {{ header()|indent(6) }}
+ {% 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 %} {{ article.content|trim }} diff --git a/pelican-theme/templates/article_footer.html b/pelican-theme/templates/article_footer.html index 5230fa88..98c10207 100644 --- a/pelican-theme/templates/article_footer.html +++ b/pelican-theme/templates/article_footer.html @@ -1 +1 @@ -

Posted{% if article.authors %} by {% for author in article.authors %}{{ author|e }}{% endfor %}{% endif %} on in {{ article.category|e }}.{% if article.modified %} updated {% endif %}{% if article.tags %} Tags: {% for tag in article.tags %}{{ tag|e }}{% if not loop.last %}, {% endif %}{% endfor %}.{% endif %}

+

Posted{% if article.authors %} by {% for author in article.authors %}{{ author|e }}{% endfor %}{% endif %} on in {{ article.category|e }}.{% if article.modified %} updated {% endif %}{% if article.archived == 'True' %} archived{% endif %}{% if article.tags %} Tags: {% for tag in article.tags %}{{ tag|e }}{% if not loop.last %}, {% endif %}{% endfor %}.{% endif %}

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 index 00000000..ff72c3d6 --- /dev/null +++ b/pelican-theme/test/blog_archived_article/article-jumbo.html @@ -0,0 +1,75 @@ + + + + + A jumbo article | A Pelican Blog + + + + + + +
+
+
+
+
+
+
+
+
Jan 16, 1982
+
+
+ +
+
+
+
+
+
+
+

Article content.

+
+
+
+
+
+
+
+
+ This article is from 1982. It's old. Deal with it.
+ +

Article content.

+ +
+
+
+
+
+
+

Posted on in misc. archived

+
+
+
+
+ +
+ + 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 index 00000000..39de9624 --- /dev/null +++ b/pelican-theme/test/blog_archived_article/article-jumbo.rst @@ -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 index 00000000..23a5f992 --- /dev/null +++ b/pelican-theme/test/blog_archived_article/article.html @@ -0,0 +1,52 @@ + + + + + An article | A Pelican Blog + + + + + + +
+
+
+
+ + +
+
+
+ + diff --git a/pelican-theme/test/blog_archived_article/article.rst b/pelican-theme/test/blog_archived_article/article.rst new file mode 100644 index 00000000..a91825e4 --- /dev/null +++ b/pelican-theme/test/blog_archived_article/article.rst @@ -0,0 +1,7 @@ +An article +########## + +:date: 1982-01-16 +:archived: True + +Article content. diff --git a/pelican-theme/test/test_blog.py b/pelican-theme/test/test_blog.py index 9c01e763..c8270a59 100644 --- a/pelican-theme/test/test_blog.py +++ b/pelican-theme/test/test_blog.py @@ -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')) -- 2.30.2