How to add images to Pelican?

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

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

and 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' 

.Html files are written to the output/YYYY/MM/ directory, where markdown is interpreted as:

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

in .html , while images are written to the output/images folder.

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

Any help would be appreciated.

+5
source share
1 answer

Make sure you use {attach} , not {filename} .

In addition, if you have energy.png in the same folder as blogpost.md , then {attach} will work. In your example, you should have energy.png in a subfolder of images.

The documentation states that you should be careful when attaching images to multiple pages. If energy.png only located {attached} -ed before blogpost.md , then it will be published along with the resulting HTML file. Otherwise, it can be moved to a place if otherblogpost.md did not expect this to happen if all the files are not in the same directory, which will not happen in your case (where the received html files are in date subfolders),

+1
source

Source: https://habr.com/ru/post/1244254/


All Articles