From d27812adc119d089a348aef326256e2971bb2b89 Mon Sep 17 00:00:00 2001 From: Kévin Le Gouguec Date: Sat, 9 Jul 2022 16:17:37 +0200 Subject: Add support for overriding thumbnail positioning --- build-concerts.py | 16 +++++++++++++--- concerts.in | 1 + en/concerts.in | 1 + helpers.py | 12 +++++++++++- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/build-concerts.py b/build-concerts.py index ed37864..e1acfde 100755 --- a/build-concerts.py +++ b/build-concerts.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 +from collections import OrderedDict from datetime import datetime from pathlib import Path from sys import argv @@ -45,7 +46,7 @@ THUMBNAILS_TEMPLATE = '''\ THUMBNAIL_TEMPLATE = '''\
- {pic_alt} +

{summary}

@@ -88,11 +89,20 @@ def format_thumbnail(concert, imgdir, lang): alt_prefix = LOCALIZED_TEXT[lang]['alt'] + pic_attributes = OrderedDict(( + ('src', Path(imgdir, 'concerts', concert.illustration.file)), + ('alt', f'{alt_prefix} {concert.illustration.alt_text}'), + ('style', concert.illustration.style), + )) + return THUMBNAIL_TEMPLATE.format_map({ 'eventclasses': ' '.join(eventclasses), 'eventid': f'concert-{concert.time.strftime("%F")}', - 'pic_file': Path(imgdir, 'concerts', concert.illustration.file), - 'pic_alt': f'{alt_prefix} {concert.illustration.alt_text}', + 'pic_attributes': ' '.join( + f'{key}="{value}"' + for key, value in pic_attributes.items() + if value is not None + ), 'summary': summary, 'credits': format_credits(concert.illustration) }) diff --git a/concerts.in b/concerts.in index 14d4c32..bf34a6a 100644 --- a/concerts.in +++ b/concerts.in @@ -257,3 +257,4 @@ légende : Plage et falaise des Petites Dalles source : Superjuju10 lien : https://commons.wikimedia.org/wiki/File:Les_Petites_Dalles_03.jpg licence : CC BY-SA 3.0 +position : 50% 35% diff --git a/en/concerts.in b/en/concerts.in index d066472..3e6c318 100644 --- a/en/concerts.in +++ b/en/concerts.in @@ -257,3 +257,4 @@ légende : Beach and cliff of the Petites Dalles source : Superjuju10 lien : https://commons.wikimedia.org/wiki/File:Les_Petites_Dalles_03.jpg licence : CC BY-SA 3.0 +position : 50% 35% diff --git a/helpers.py b/helpers.py index fed585b..ab93699 100644 --- a/helpers.py +++ b/helpers.py @@ -68,6 +68,7 @@ class Illustration: source_name: str source_link: Optional[str] license_info: Optional[LicenseInfo] + position: Optional[str] @classmethod def deserialize(cls, d): @@ -75,7 +76,15 @@ class Illustration: d['pic_alt'], d['pic_src'], d['pic_link'], - LicenseInfo.deserialize(d['pic_license'])) + LicenseInfo.deserialize(d['pic_license']), + d['pic_position']) + + @property + def style(self): + if self.position is None: + return None + + return f'object-position: {self.position}' @dataclass @@ -120,6 +129,7 @@ _CONCERT_LINES = ( r'source : (?P[^\n]+)\n', _optional(r'lien : (?P[^\n]+)\n'), _optional(r'licence : (?P[^\n]+)\n'), + _optional(r'position : (?P[^\n]+)\n'), _optional(r'AVERTISSEMENT : (?P[^\n]+)\n'), ) -- cgit v1.2.3