chiark / gitweb /
theme: ability to control article expansion and summary appearance.
authorVladimír Vondruš <mosra@centrum.cz>
Wed, 6 Dec 2017 11:36:58 +0000 (12:36 +0100)
committerVladimír Vondruš <mosra@centrum.cz>
Wed, 6 Dec 2017 11:42:39 +0000 (12:42 +0100)
doc/examples/article-hide-summary.rst [new file with mode: 0644]
doc/examples/jumbo-article-hide-summary.rst [new file with mode: 0644]
doc/pelican/theme.rst
pelican-theme/templates/archives.html
pelican-theme/templates/article.html
pelican-theme/templates/article_header.html
pelican-theme/templates/index.html

diff --git a/doc/examples/article-hide-summary.rst b/doc/examples/article-hide-summary.rst
new file mode 100644 (file)
index 0000000..37c997a
--- /dev/null
@@ -0,0 +1,50 @@
+..
+    This file is part of m.css.
+
+    Copyright © 2017 Vladimír Vondruš <mosra@centrum.cz>
+
+    Permission is hereby granted, free of charge, to any person obtaining a
+    copy of this software and associated documentation files (the "Software"),
+    to deal in the Software without restriction, including without limitation
+    the rights to use, copy, modify, merge, publish, distribute, sublicense,
+    and/or sell copies of the Software, and to permit persons to whom the
+    Software is furnished to do so, subject to the following conditions:
+
+    The above copyright notice and this permission notice shall be included
+    in all copies or substantial portions of the Software.
+
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+    THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+    DEALINGS IN THE SOFTWARE.
+..
+
+Article with hidden summary
+###########################
+
+.. role:: language-la
+    :class: language-la
+
+:date: 2017-12-06 0:00
+:category: Examples
+:tags: Special
+:author: An Author
+:slug: article-hide-summary
+:hide_summary: True
+
+Implicit article summary paragraph. :language-la:`Lorem ipsum dolor sit amet,
+consectetur adipiscing elit. Aenean id elit posuere, consectetur magna congue,
+sagittis est.`
+
+Article contents. :language-la:`Pellentesque est neque, aliquet nec consectetur
+in, mattis ac diam. Aliquam placerat justo ut purus interdum, ac placerat lacus
+consequat. Mauris id suscipit mauris, in scelerisque lectus. Aenean nec nunc eu
+sem tincidunt imperdiet ut non elit. Integer nisi tellus, ullamcorper vitae
+euismod quis, venenatis eu nulla.`
+
+.. note-info::
+
+    Compare the look to an `article containing explicit summary <{filename}/examples/article.rst>`_.
diff --git a/doc/examples/jumbo-article-hide-summary.rst b/doc/examples/jumbo-article-hide-summary.rst
new file mode 100644 (file)
index 0000000..d893a83
--- /dev/null
@@ -0,0 +1,51 @@
+..
+    This file is part of m.css.
+
+    Copyright © 2017 Vladimír Vondruš <mosra@centrum.cz>
+
+    Permission is hereby granted, free of charge, to any person obtaining a
+    copy of this software and associated documentation files (the "Software"),
+    to deal in the Software without restriction, including without limitation
+    the rights to use, copy, modify, merge, publish, distribute, sublicense,
+    and/or sell copies of the Software, and to permit persons to whom the
+    Software is furnished to do so, subject to the following conditions:
+
+    The above copyright notice and this permission notice shall be included
+    in all copies or substantial portions of the Software.
+
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+    THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+    DEALINGS IN THE SOFTWARE.
+..
+
+Article with hidden summary --- a jumbo one
+###########################################
+
+.. role:: language-la
+    :class: language-la
+
+:cover: {filename}/static/ship.jpg
+:date: 2017-12-06 1:00
+:category: Examples
+:tags: Jumbo, Special
+:author: An Author
+:slug: jumbo-article-hide-summary
+:hide_summary: True
+
+Implicit article summary paragraph. :language-la:`Lorem ipsum dolor sit amet,
+consectetur adipiscing elit. Aenean id elit posuere, consectetur magna congue,
+sagittis est.`
+
+Article contents. :language-la:`Pellentesque est neque, aliquet nec consectetur
+in, mattis ac diam. Aliquam placerat justo ut purus interdum, ac placerat lacus
+consequat. Mauris id suscipit mauris, in scelerisque lectus. Aenean nec nunc eu
+sem tincidunt imperdiet ut non elit. Integer nisi tellus, ullamcorper vitae
+euismod quis, venenatis eu nulla.`
+
+.. note-info::
+
+    Compare the look to a `jumbo article containing explicit summary <{filename}/examples/jumbo-article.rst>`_.
index d8c886b08eeca41e0db393a1ab166a6e4383f0b4..470a65bd2959d4fd22828b73130e9e749bb905c4 100644 (file)
@@ -492,6 +492,55 @@ supported in a similar way:
     URL of e.g. the `jumbo article`_ into either `Facebook Debugger`_ or
     `Twitter Card Validator`_.
 
+`Controlling article appearance`_
+---------------------------------
+
+By default, the theme assumes that you provide an explicit :rst:`:summary:`
+field for each article. The summary is then displayed on article listing page
+and also prepended to fully expanded article. If your :rst:`:summary:` is
+automatically generated by Pelican or for any other reason repeats article
+content, it might not be desirable to show it in combination with article
+content. This can be configured via the following setting:
+
+.. code:: py
+
+    M_HIDE_ARTICLE_SUMMARY = True
+
+There's also a possibility to control this on a per-article basis by setting
+:rst:`:hide_summary:` to either :py:`True` or :py:`False`. If both global and
+per-article setting is present, article-specific setting has a precedence.
+Example:
+
+.. code:: rst
+
+    An article without explicit summary
+    ###################################
+
+    :cover: {filename}/static/ship.jpg
+    :hide_summary: True
+
+    Implicit article summary paragraph.
+
+    Article contents.
+
+.. note-info::
+
+    Here's the visual appearance of an `article without explicit summary <{filename}/examples/article-hide-summary.rst>`_
+    and a corresponding `jumbo article <{filename}/examples/jumbo-article-hide-summary.rst>`__.
+
+As noted above, the first article is by default fully expanded on index and
+archive page. However, sometimes the article is maybe too long to be expanded
+or you might want to not expand any article at all. This can be controlled
+either globally using the following setting:
+
+.. code:: py
+
+    M_COLLAPSE_FIRST_ARTICLE = True
+
+Or, again, on a per-article basis, by setting :rst:`:collapse_first:` to either
+:py:`True` or :py:`False`. If both global and per-article setting is present,
+article-specific setting has a precedence.
+
 `Pre-defined pages`_
 ====================
 
index bc7f0fd7ee1459cc79e6cba07e872b0a0ca37c3a..28f5268e064f7325615f33fee6f44ea9b2b89044 100644 (file)
@@ -18,7 +18,9 @@
       <article>
         {% macro header() %}{% include "article_header.html" %}{% endmacro %}
         {{ header()|indent(8) }}
-        {% if loop.first and articles_page.number == 1 %}
+        {% if loop.first and articles_page.number == 1 and
+              ((article.collapse_first is defined and article.collapse_first != 'True') or
+               (article.collapse_first is not defined and not M_COLLAPSE_FIRST_ARTICLE)) %}
         <div class="m-clearfix-l"></div>
 <!-- content -->
 {{ article.content }}
index c948f4e77f57e69531627e0ee7b6f13e86e60378..4a3e47ccaf8e2fa2a19196b3719f03448b7ac3d6 100644 (file)
@@ -49,6 +49,8 @@
           </div>
         </div>
       </div>
+      {% if (article.hide_summary is defined and article.hide_summary != 'True') or
+            (article.hide_summary is not defined and not M_HIDE_ARTICLE_SUMMARY) %}
       <div class="m-container">
         <div class="m-row">
           <div class="m-col-m-10 m-push-m-1 m-nopady">
@@ -56,6 +58,7 @@
           </div>
         </div>
       </div>
+      {% endif %}
     </header>
     <div class="m-container m-container-inflatable">
       <div class="m-row">
index fd782411bc14dad9f958eb2ea360e7a5d383cc3e..a05b659a81c0f6662ef67d9941386f7f1178a245 100644 (file)
@@ -6,5 +6,19 @@
     </time>
     {{ article.title }}
   </a></h1>
+  {# Display summary only if:
+    - we're on article listing page and the article is not expanded (it's
+      expanded only if it's first on the first page only on the index/archive
+      page and only if it doesn't say it should be collapsed)
+    - the article is expanded but doesn't say the summary should be hidden #}
+  {% if (articles_page and
+         (page_name not in ['index', 'archives'] or
+          not loop.first or
+          articles_page.number != 1 or
+          (article.collapse_first is defined and article.collapse_first == 'True') or
+          (article.collapse_first is not defined and M_COLLAPSE_FIRST_ARTICLE))) or
+        (article.hide_summary is defined and article.hide_summary != 'True') or
+        (article.hide_summary is not defined and not M_HIDE_ARTICLE_SUMMARY) %}
   {{ article.summary|indent(2) }}
+  {% endif %}
 </header>
index bc7f0fd7ee1459cc79e6cba07e872b0a0ca37c3a..28f5268e064f7325615f33fee6f44ea9b2b89044 100644 (file)
@@ -18,7 +18,9 @@
       <article>
         {% macro header() %}{% include "article_header.html" %}{% endmacro %}
         {{ header()|indent(8) }}
-        {% if loop.first and articles_page.number == 1 %}
+        {% if loop.first and articles_page.number == 1 and
+              ((article.collapse_first is defined and article.collapse_first != 'True') or
+               (article.collapse_first is not defined and not M_COLLAPSE_FIRST_ARTICLE)) %}
         <div class="m-clearfix-l"></div>
 <!-- content -->
 {{ article.content }}