getpelican / pelican-plugins

Collection of plugins for the Pelican static site generator
Other
1.39k stars 846 forks source link

[Neighbor articles]. Cannot deal with drafts #909

Closed jorgesumle closed 6 years ago

jorgesumle commented 7 years ago

Maybe it would be better to add an empty URL for the draft, I don't know what's the best way to deal with this problem. Here is the error I got when I tried to generate the website with an article with the Status set as draft:


CRITICAL: UndefinedError: 'pelican.contents.Draft object' has no attribute 'next_article'

Useful: Section about drafts in Pelican's documentation: http://docs.getpelican.com/en/stable/content.html#publishing-drafts

justinmayer commented 6 years ago

@jorgesumle: Is this something you would like to work on?

jorgesumle commented 6 years ago

I don't have much free time now, and I need to understand the code first, but maybe in the future. If someone else can fix it, it would be great.

avaris commented 6 years ago

@jorgesumle where exactly do you get this error? Can you show full traceback with --debug option?

jorgesumle commented 6 years ago

@avaris, sure. Here you are:

[... Writing stuff]
-> Writing /var/www/html/Repositorios/Freak-Spot/output/author/ren-canteros-sousa/index.html
CRITICAL: UndefinedError: 'pelican.contents.Draft object' has no attribute 'next_article'
Traceback (most recent call last):
  File "/usr/local/bin/pelican", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.6/dist-packages/pelican/__init__.py", line 487, in main
    pelican.run()
  File "/usr/local/lib/python3.6/dist-packages/pelican/__init__.py", line 179, in run
    p.generate_output(writer)
  File "/usr/local/lib/python3.6/dist-packages/pelican/generators.py", line 600, in generate_output
    self.generate_pages(writer)
  File "/usr/local/lib/python3.6/dist-packages/pelican/generators.py", line 502, in generate_pages
    self.generate_drafts(write)
  File "/usr/local/lib/python3.6/dist-packages/pelican/generators.py", line 485, in generate_drafts
    blog=True, all_articles=self.articles)
  File "/usr/local/lib/python3.6/dist-packages/pelican/writers.py", line 230, in write_file
    override_output)
  File "/usr/local/lib/python3.6/dist-packages/pelican/writers.py", line 171, in _write_file
    output = template.render(localcontext)
  File "/usr/local/lib/python3.6/dist-packages/jinja2/asyncsupport.py", line 76, in render
    return original_render(self, *args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/jinja2/environment.py", line 1008, in render
    return self.environment.handle_exception(exc_info, True)
  File "/usr/local/lib/python3.6/dist-packages/jinja2/environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.6/dist-packages/jinja2/_compat.py", line 37, in reraise
    raise value.with_traceback(tb)
  File "/var/www/html/Repositorios/Freak-Spot/freak-theme/templates/article.html", line 1, in top-level template code
    {% extends "base.html" %}
  File "/var/www/html/Repositorios/Freak-Spot/freak-theme/templates/base.html", line 4, in top-level template code
    {% block head %}
  File "/var/www/html/Repositorios/Freak-Spot/freak-theme/templates/article.html", line 48, in block "head"
    {% if article.next_article.image or article.prev_article.image %}
  File "/usr/local/lib/python3.6/dist-packages/jinja2/environment.py", line 430, in getattr
    return getattr(obj, attribute)
jinja2.exceptions.UndefinedError: 'pelican.contents.Draft object' has no attribute 'next_article'
avaris commented 6 years ago

@jorgesumle I'd say this is a theme issue. Drafts aren't in the prev/next chain and it doesn't really make sense for them to be anyways. I'd recommend a bit more fault tolerant theme that checks the existence of next_article and prev_article first:

{% if (article.next_article and article.next_article.image) or (article.prev_article and article.prev_article.image) %}
jorgesumle commented 6 years ago

You're right @avaris, it's a theme issue. I've fixed it giving you attribution in the commit message. Thanks!