private = True | private = True | ||||
slug = f"{slug}-{password}" | slug = f"{slug}-{password}" | ||||
photos = list(list_photos_in(gallery_dir, slug)) | |||||
photos = list(list_photos_in(gallery_dir, metadata, slug)) | |||||
if not photos: | if not photos: | ||||
continue | continue | ||||
photos.sort(key=itemgetter("name")) | photos.sort(key=itemgetter("name")) | ||||
return None | return None | ||||
def list_photos_in(gallery_dir, gallery_slug): | |||||
def list_photos_in(gallery_dir, gallery_metadata, gallery_slug): | |||||
photo_files = [ | photo_files = [ | ||||
f for f in os.scandir(gallery_dir) if re.match(".+\.jpg", f.name, re.I) | f for f in os.scandir(gallery_dir) if re.match(".+\.jpg", f.name, re.I) | ||||
] | ] | ||||
with Image.open(photo_file.path) as image: | with Image.open(photo_file.path) as image: | ||||
width, height = image.size | width, height = image.size | ||||
name = Path(photo_file.name).stem | name = Path(photo_file.name).stem | ||||
metadata = gallery_metadata.get(name, {}) | |||||
page_url = f"{gallery_slug}-{name}.html" | page_url = f"{gallery_slug}-{name}.html" | ||||
photo = { | photo = { | ||||
"gallery_slug": gallery_slug, | "gallery_slug": gallery_slug, | ||||
"height": height, | "height": height, | ||||
"narrow": height > width, | "narrow": height > width, | ||||
"wide": height * 2 < width, | "wide": height * 2 < width, | ||||
"alt": metadata.get("alt", ""), | |||||
} | } | ||||
yield photo | yield photo | ||||
{%- endfor -%} | {%- endfor -%} | ||||
" | " | ||||
sizes="min((100vw - 2rem), 330px)" | sizes="min((100vw - 2rem), 330px)" | ||||
alt="TODO" loading="lazy" decoding="async"> | |||||
alt="{{ gallery.cover_photo.alt or 'TODO' }}" loading="lazy" decoding="async"> | |||||
<figcaption>{{ gallery.name }}</figcaption> | <figcaption>{{ gallery.name }}</figcaption> | ||||
</picture> | </picture> | ||||
</a> | </a> |
sizes="min(100vw, calc(100vh * {{ photo.width }} / {{ photo.height }}))" | sizes="min(100vw, calc(100vh * {{ photo.width }} / {{ photo.height }}))" | ||||
fetchpriority="high" | fetchpriority="high" | ||||
decoding="sync" | decoding="sync" | ||||
alt="TODO"> | |||||
alt="{{ photo.alt or 'TODO' }}"> | |||||
</picture> | </picture> | ||||
</div> | </div> | ||||
<h1>{{ gallery.name }}{% if gallery.private %} (🔒 privé){% endif %}</h1> | <h1>{{ gallery.name }}{% if gallery.private %} (🔒 privé){% endif %}</h1> | ||||
{% if photo.alt %} | |||||
<h2>{{ photo.alt }}</h2> | |||||
{% endif %} | |||||
<nav> | <nav> | ||||
<p class="u-center"> | <p class="u-center"> | ||||
{% if previous %} | {% if previous %} | ||||
<a href="{{ previous.page_url }}" | <a href="{{ previous.page_url }}" | ||||
title="Photo précédente, vous pouvez utiliser la flèche du clavier ←" | title="Photo précédente, vous pouvez utiliser la flèche du clavier ←" | ||||
rel="prev" | |||||
data-navigation-target="previous" | data-navigation-target="previous" | ||||
>← Photo précédente</a> | >← Photo précédente</a> | ||||
• | • | ||||
• | • | ||||
<a href="{{ next.page_url }}" | <a href="{{ next.page_url }}" | ||||
title="Photo suivante, vous pouvez utiliser la flèche du clavier →" | title="Photo suivante, vous pouvez utiliser la flèche du clavier →" | ||||
rel="next" | |||||
data-navigation-target="next" | data-navigation-target="next" | ||||
>Photo suivante →</a> | >Photo suivante →</a> | ||||
{% endif %} | {% endif %} |
font-size: 2rem; | font-size: 2rem; | ||||
line-height: 2.5rem; | line-height: 2.5rem; | ||||
} | } | ||||
h2 { | |||||
text-align: center; | |||||
margin-bottom: 1.75rem; | |||||
} | |||||
img { | img { | ||||
max-width: 100%; | max-width: 100%; |