Skip to content

Commit

Permalink
theme: support for archived articles.
Browse files Browse the repository at this point in the history
  • Loading branch information
mosra committed Jan 16, 2018
1 parent a5a1755 commit 5e6bd5b
Show file tree
Hide file tree
Showing 8 changed files with 185 additions and 1 deletion.
20 changes: 20 additions & 0 deletions doc/pelican/theme.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`_
----------------------------------

Expand Down
6 changes: 6 additions & 0 deletions pelican-theme/templates/article.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ <h2>{{ title[1] }}</h2>
<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 -->
Expand All @@ -111,6 +114,9 @@ <h2>{{ title[1] }}</h2>
{% 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 }}
Expand Down
2 changes: 1 addition & 1 deletion pelican-theme/templates/article_footer.html
Original file line number Diff line number Diff line change
@@ -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>
75 changes: 75 additions & 0 deletions pelican-theme/test/blog_archived_article/article-jumbo.html
Original file line number Diff line number Diff line change
@@ -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>
8 changes: 8 additions & 0 deletions pelican-theme/test/blog_archived_article/article-jumbo.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
A jumbo article
###############

:date: 1982-01-16
:cover: image.jpg
:archived: True

Article content.
52 changes: 52 additions & 0 deletions pelican-theme/test/blog_archived_article/article.html
Original file line number Diff line number Diff line change
@@ -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>
7 changes: 7 additions & 0 deletions pelican-theme/test/blog_archived_article/article.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
An article
##########

:date: 1982-01-16
:archived: True

Article content.
16 changes: 16 additions & 0 deletions pelican-theme/test/test_blog.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,3 +494,19 @@ def test(self):
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'))

0 comments on commit 5e6bd5b

Please sign in to comment.