pelican-plugins / series

Series is a Pelican plugin that joins multiple posts into a series
11 stars 4 forks source link

series breaks on draft articles #31

Open mpounsett opened 1 year ago

mpounsett commented 1 year ago

This is similar to #18, although the specifics I'm seeing are slightly different than what was described there.

I've got a draft article with my first series in it.. and just added series support to my theme. My pelicanconf.py defines DEFAULT_METADATA of "status": "published" for development purposes, and publishconf.py sets that default to draft. This is the setup I use so that the devserver will show me draft articles as they will appear once published. My uses of pelican-series worked fine in this setup until I tried to do a producton publish of a new article, while the unfinished series article is still in drafts.

When Pelican's make publish target hits that draft article, it fails. The first encountered error is a reference to article.series.previous.url:

UndefinedError: 'str object' has no attribute 'previous'

The error comes from this bit of template in my article.html:

{% if article.series.previous is not none %}
    <a class="series-footer text-muted"
       href="{{ SITEURL }}/{{ article.series.previous.url }}">
        <i class="fa fa-angles-left"></i>
        Previous Article
    </a>
{% else %}
    <i class="fa fa-angles-left"></i>
    Previous Article
{% endif %}

That block is itself wrapped in an if to check whether the article is part of a series:

{% if SHOW_SERIES and article.series is defined %}

The draft in question is the first and only article in the series, so article.series.next and article.series.previous should both be None. I've done some strategic commenting-out of bits of the template and inserting values as comments to determine that article.series.previous actually references article.series.name in a draft, rather than article.series.all_previous[-1], as it does when the article is published.

Oddly, article.series.index and article.series.name both seem to be empty string when the document is a draft, but work as expected when the document is published.

Relevant software version info from my virtualenv:

% python --version
Python 3.10.9

% pip freeze
blinker==1.5
commonmark==0.9.1
docutils==0.19
feedgenerator==2.0.0
Jinja2==3.1.2
MarkupSafe==2.1.1
pelican==4.8.0
pelican-i18n-subsites==0.9.0
pelican-series==2.1.0
pelican-youtube==0.2.1
Pygments==2.13.0
python-dateutil==2.8.2
pytz==2022.7
rich==13.0.0
six==1.16.0
smartypants==2.0.1
typogrify==2.0.7
Unidecode==1.3.6
lgiordani commented 7 months ago

@mpounsett I'm so sorry I ignored this error for so long. Would you be able to provide a GH repo with a minimal example of the situation? This way it will be very easy to debug. Thanks, and again so sorry for the delay.