How do I attach images in Pelican?
Asked Answered
T

1

8

I am trying to attach an image in Pelican, following the documentation here. Here is the markdown:

![energy]({filename}images/energy.png)

and the pelicanconf.py:

PATH = 'content'
STATIC_PATHS = ['images', 'pdfs']
ARTICLE_URL = 'blog/{date:%Y}/{date:%m}/{slug}.html'
ARTICLE_SAVE_AS = 'blog/{date:%Y}/{date:%m}/{slug}.html'

The .html files are written into output/YYYY/MM/ directory where the markdown gets interpreted as:

<img alt="energy" src="{filename}/images/energy.png"/>

in the .html while the images are written into output/images folder.

So the HTML files cannot find the images. How do I fix it? Ideally, I would like to store the images in the same folder as the .html files (I think that is what {attach} does).

Any help would be appreciated.

Tussis answered 1/3, 2016 at 21:5 Comment(0)
R
3

Make sure you are using {attach} and not {filename}.

Also, if you have energy.png in the same folder as blogpost.md then {attach} will work. With your example you must have energy.png in the images subfolder.

The documentation states that you should be careful of images being attached to multiple pages. If energy.png is only being {attached}-ed to blogpost.md then it will get published alongside the resulting HTML file. Otherwise it may be moved to a place were otherblogpost.md won't expect it to be, unless all files are in the same directory, which is not going to happen in your case (where the resulting html files are in the date subfolders).

Ranson answered 2/3, 2016 at 22:24 Comment(2)
{attach} is not recognized at all; I get the following error message: ERROR: Better Fig. Error: image not found: [~]/pelican/content/{attach}energy.png when the image and markdown are in the same folder. I am using pelican 3.6.3, so that is strange.Tussis
Removed Better figures but now it cannot find the image: WARNING: Unable to find energy.png, skipping url replacement. I also tried putting it in images/energy.png, which is where I would prefer it go so as to not clutter the content directory.Tussis

© 2022 - 2024 — McMap. All rights reserved.