From a118c995e937603b13df3bd38addd44d69b76ac0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abel=20Alfonso=20F=C3=ADrvida=20Don=C3=A9stevez?= Date: Mon, 16 Mar 2020 14:41:03 -0400 Subject: [PATCH] Add image tag for cover image of articles. So many blogs may need cover image in their articles. In this commit we add a way to insert image in the article metadata. Also an example of how to use it in a theme is added to the simple theme. --- pelican/generators.py | 1 + pelican/readers.py | 4 +++- pelican/themes/simple/templates/article.html | 3 +++ pelican/writers.py | 1 + 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/pelican/generators.py b/pelican/generators.py index 02667cd7..ae6f1bb1 100644 --- a/pelican/generators.py +++ b/pelican/generators.py @@ -286,6 +286,7 @@ class ArticlesGenerator(CachingGenerator): self.categories = defaultdict(list) self.related_posts = [] self.authors = defaultdict(list) + self.images = defaultdict(list) self.drafts = [] # only drafts in default language self.drafts_translations = [] super().__init__(*args, **kwargs) diff --git a/pelican/readers.py b/pelican/readers.py index 673b637e..dff607c5 100644 --- a/pelican/readers.py +++ b/pelican/readers.py @@ -42,7 +42,8 @@ DUPLICATES_DEFINITIONS_ALLOWED = { 'save_as': False, 'url': False, 'authors': False, - 'slug': False + 'slug': False, + 'image': False } METADATA_PROCESSORS = { @@ -60,6 +61,7 @@ METADATA_PROCESSORS = { for author in ensure_metadata_list(x) ] or _DISCARD), 'slug': lambda x, y: x.strip() or _DISCARD, + 'image': lambda x, y: x.strip() or _DISCARD } logger = logging.getLogger(__name__) diff --git a/pelican/themes/simple/templates/article.html b/pelican/themes/simple/templates/article.html index 5a1c093d..49d9d915 100644 --- a/pelican/themes/simple/templates/article.html +++ b/pelican/themes/simple/templates/article.html @@ -30,6 +30,9 @@ {% import 'translations.html' as translations with context %} {{ translations.translations_for(article) }} + {% if article.image %} + + {% endif %}