Pelican image format issues
I was working on my article about setting up Pelican on PythonAnywhere and after I ran:
make html
That all my images disappeared. The alt text was displaying but no images.
Weird.
Given that I just wrote an article about how to set Pelican up I figured that I really should get to the bottom of this or it might end up on thedailywtf or something. So I clicked on view image info and I saw the following:
https://www.lesinskis.com/%7Bfilename%7D/images/pelican_on_PA_static_settings.png
The first place I looked was the .rst file the article was written in:
.. image:: {filename}/images/pelican_on_PA_static_settings.png :alt: image showing the PythonAnywhere static files setup.
It looked fine but given it wasn't working that clearly wasn't good enough. I'd just finished a flurry of commits and small edits so I wanted to check that I hadn't accidentally changed anything. So I ran:
git log pelican_on_pythonanywhere.rst
Nothing had changed on that line.
So I figured I'd run make html again and see what happened:
01:20 ~/pelican_site (master)$ make html pelican /home/janis/pelican_site/content -o /home/janis/pelican_site/output -s /home/janis/pelican_site/pelicanconf.py WARNING: AUTHOR_SAVE_AS is set to False Done: Processed 11 articles and 1 pages in 15.13 seconds.
At this point I realized I wasn't working in the virtual environment I set up.
So I ran the following commands:
01:24 ~/pelican_site (master)$ pip show Pelican --- Name: pelican Version: 3.2.2 Location: /usr/local/lib/python2.7/dist-packages Requires: feedgenerator, jinja2, pygments, docutils, pytz, blinker, unidecode, six 01:24 ~/pelican_site (master)$ workon pelican (pelican)01:27 ~/pelican_site (master)$ pip show Pelican --- Name: pelican Version: 3.3 Location: /home/janis/.virtualenvs/pelican/lib/python2.7/site-packages Requires: feedgenerator, jinja2, pygments, docutils, pytz, blinker, unidecode, six
So we can see that the default-installed Pelican is a different version to the one in the virtual environment. Making sure that I was in the virtual environment, I generated the site again:
(pelican)01:27 ~/pelican_site (master)$ make html pelican /home/janis/pelican_site/content -o /home/janis/pelican_site/output -s /home/janis/pelican_site/pelicanconf.py WARNING: AUTHOR_SAVE_AS is set to False Done: Processed 11 articles and 1 pages in 15.38 seconds.
This time everything worked fine but it left me wondering why this particular symptom occurred.
Why the images disappeared?
You will notice above that when we generated the site with the wrong version of Pelican that the image path wasn't correctly generated. You see in the image path %7Bfilename%7D which is clearly not what we want. This translates to {filename}. So I realized that the .rst file just wasn't being correctly processed so I searched the internet to see if I could find out more.
I found a discussion of the issue here.
Basically the curly brace {filename} way of linking to internal content was new to Pelican 3.3. So when I ran make html using Pelican 3.2.2 it didn't recognize this format and hence just put it in the image path without processing.
Hopefully this helps anyone who runs into the same issue.