Organize gallery into highlighted photo groups

This commit is contained in:
2026-09-19 18:13:48 +03:30
parent 3ec6cdd3ec
commit b6b19c07bb
30 changed files with 335 additions and 66 deletions
+30 -16
View File
@@ -10,7 +10,7 @@ from pathlib import Path
import re
import shutil
import tempfile
from datetime import datetime, timezone
from datetime import datetime, timedelta, timezone
import warnings
import zipfile
@@ -79,6 +79,26 @@ def web_image(raw, destination):
Image.Resampling.LANCZOS)
def photo_entry(job, date, index, count, caption, highlight):
# Give each photo its own collection document. Descending dates preserve the
# selection order because the gallery renders the newest document first.
item_date = datetime.fromisoformat(date) + timedelta(microseconds=count - index)
title = f"photo-{job}" if index == 0 else f"photo-{job}-{index:02}"
content = ["---", "layout: post", f'title: "{title}"',
f'date: "{item_date.isoformat()}"', "categories: art"]
if index == 0 and highlight:
content.append(f"anchor: {json.dumps(highlight)}")
content.extend(["---", ""])
if index == 0 and not highlight:
content.extend([f'<div id="photo-{job}"></div>', ""])
content.append(f'<p><img src="/img/arts/uploads/{job}/{index:02}.jpg" '
f'alt="{public_text(caption)}" loading="lazy"></p>')
if caption:
content.append('<span class="image-details">' +
public_text(caption).replace("\n", "<br>") + "</span>")
return "\n".join(content) + "\n"
def create_app(data_dir=None, token=None):
app = Flask(__name__)
app.config.update(MAX_CONTENT_LENGTH=100 * 1024 * 1024,
@@ -261,21 +281,15 @@ def create_app(data_dir=None, token=None):
if kind == "snippet":
manifest.update(kind=kind, text=text)
atomic_json(temporary / "manifest.json", manifest)
content = ["---", "layout: post", f'title: "photo-{job}"',
f'date: "{date}"', "categories: art"]
if highlight:
content.append(f"anchor: {json.dumps(highlight)}")
content.extend(["---", ""])
# The gallery already renders an anchor before the first photo for highlights.
if not highlight:
content.extend([f'<div id="photo-{job}"></div>', ""])
for index in range(len(photos)):
content.append(f'<p><img src="/img/arts/uploads/{job}/{index:02}.jpg" '
f'alt="{public_text(caption)}" loading="lazy"></p>')
if caption:
content.append('<span class="image-details">' +
public_text(caption).replace("\n", "<br>") + "</span>")
if kind == "snippet":
if kind == "photo":
(temporary / "entries").mkdir()
for index in range(len(photos)):
(temporary / "entries" / f"{index:02}.md").write_text(
photo_entry(job, date, index, len(photos), caption, highlight))
# Retain the old filename for compatibility with publisher versions
# that predate one-document-per-photo submissions.
content = [(temporary / "entries/00.md").read_text()]
else:
content = [f'<div id="snippet-{job}"></div>', ""]
for paragraph in (text, caption):
if paragraph: