getpelican / pelican

Static site generator that supports Markdown and reST syntax. Powered by Python.
https://getpelican.com
GNU Affero General Public License v3.0
12.58k stars 1.81k forks source link

How to differentiate between manual and automatic article.summary? #2293

Closed peterdesmet closed 6 years ago

peterdesmet commented 6 years ago

For a theme I'm creating, I want to use the metadata summary as a lead paragraph for articles/pages:

{% if article.summary %}
    <div class="lead">
        {{ article.summary }}
    </div>
{% endif %}

Pelican however always sets a summary for articles/pages, either from the metadata summary or from the content (using SUMMARY_MAX_LENGTH). Here however, I don't want to show the automatically generated summary, but only the manually set one. Is there a way to differentiate between the two?


Note: one could leave the summary tag empty, but then articles in an index.html no longer get their automatic summary. I'm currently thinking of dropping summary altogether, and using the custom metadata tag intro. For index.html I will then use:

{% if article.intro %}
    {{ article.intro|striptags }}<!-- from metadata -->
{% else %}
    {{ article.summary|striptags }}<!-- automatic -->
{% endif %}

But I'd rather use something more straightforward. 😄

jorgesumle commented 6 years ago

I use a modified version of the plugin another_read_more_link for that. Read its README to learn how it works.

avaris commented 6 years ago

If you don't want automated summary generation, just set SUMMARY_MAX_LENGTH = 0. You'll get empty string instead. Then, it's basically a {% if article.summary %} check after that.

peterdesmet commented 6 years ago

@jorgesumle so for pages where I don't have a manual summary and don't want an automatic summary, I'd have to place the <!-- more --> at the very top of my content?

@avaris I like the automatic summary generation, I just hoped I'd be able to differentiate between automatic and manual in my theme.

peterdesmet commented 6 years ago

This aptly named plugin can differentiate between the two: https://github.com/getpelican/pelican-plugins/tree/master/summary with has_summary. Closing issue