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.
This commit is contained in:
Abel Alfonso Fírvida Donéstevez 2020-03-16 14:41:03 -04:00
commit a118c995e9
4 changed files with 8 additions and 1 deletions

View file

@ -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)

View file

@ -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__)

View file

@ -30,6 +30,9 @@
{% import 'translations.html' as translations with context %}
{{ translations.translations_for(article) }}
</header>
{% if article.image %}
<img src="{{ article.image }}"/>
{% endif %}
<footer class="post-info">
<time class="published" datetime="{{ article.date.isoformat() }}">
{{ article.locale_date }}

View file

@ -81,6 +81,7 @@ class Writer(object):
feed.add_item(
title=title,
link=link,
image=item.image,
unique_id=get_tag_uri(link, item.date),
description=description,
content=content,