Organize gallery into highlighted photo groups
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
"""One-time migration of September 2026 uploads into individual highlighted photos."""
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from pathlib import Path
|
||||
import html
|
||||
|
||||
|
||||
ART = Path("_art")
|
||||
UPLOAD = "/img/arts/uploads"
|
||||
OLD = [
|
||||
"260cc99527c13f256d4ea39d0959f5daa942c888ea882852e73fd94f6c30b7db",
|
||||
"474ab3283ce8801ac6e59b67b65b4169167053873a5a8db4a15b840a3448266c",
|
||||
"7c832afa1b73023d8f2391ff40c221be9ffd468a1a96a6bf4900cbf95595d31d",
|
||||
"b18a2f1c7127077c801160782012cb164759f0b9dd41762205b45e4c9a07d673",
|
||||
"c53f20236f166632bff163339c8e789cc09b0d7e63c5b531b1fc20705460975b",
|
||||
]
|
||||
|
||||
armenia = [
|
||||
(OLD[2], 9), (OLD[2], 8), (OLD[2], 7), (OLD[2], 6),
|
||||
(OLD[2], 5), (OLD[2], 4), (OLD[1], 0),
|
||||
]
|
||||
romania = [
|
||||
(OLD[2], 0), (OLD[2], 1), (OLD[4], 0), (OLD[4], 1),
|
||||
(OLD[4], 2), (OLD[4], 3), (OLD[4], 4), (OLD[0], 0), (OLD[3], 0),
|
||||
]
|
||||
ungrouped = [(OLD[2], 2), (OLD[2], 3)]
|
||||
ordered = armenia + romania + ungrouped
|
||||
assert len(ordered) == len(set(ordered)) == 18
|
||||
|
||||
anchors = {armenia[0]: "Armenia", romania[0]: "Romania"}
|
||||
captions = {(OLD[2], 7): "Transmission of Flesh by Erfan Ashourioun"}
|
||||
first_for_job = {}
|
||||
for photo in ordered:
|
||||
first_for_job.setdefault(photo[0], photo)
|
||||
|
||||
for job in OLD:
|
||||
batch = next(ART.glob(f"*-photo-{job}.md"), None)
|
||||
if batch:
|
||||
batch.unlink()
|
||||
|
||||
start = datetime(2026, 9, 19, 12, 29, 33, tzinfo=timezone.utc)
|
||||
for position, (job, index) in enumerate(ordered):
|
||||
title = f"photo-{job}-{index:02}"
|
||||
if (job, index) == first_for_job[job]:
|
||||
title = f"photo-{job}"
|
||||
date = start - timedelta(microseconds=position)
|
||||
lines = ["---", "layout: post", f'title: "{title}"',
|
||||
f'date: "{date.isoformat()}"', "categories: art"]
|
||||
if (job, index) in anchors:
|
||||
lines.append(f'anchor: "{anchors[(job, index)]}"')
|
||||
lines.extend(["---", ""])
|
||||
if (job, index) == first_for_job[job] and (job, index) not in anchors:
|
||||
lines.extend([f'<div id="photo-{job}"></div>', ""])
|
||||
caption = captions.get((job, index), "")
|
||||
lines.append(f'<p><img src="{UPLOAD}/{job}/{index:02}.jpg" '
|
||||
f'alt="{html.escape(caption, quote=True)}" loading="lazy"></p>')
|
||||
if caption:
|
||||
lines.append(f'<span class="image-details">{html.escape(caption)}</span>')
|
||||
target = ART / f"2026-09-19-photo-{job}-{index:02}.md"
|
||||
target.write_text("\n".join(lines) + "\n")
|
||||
|
||||
print("Created 18 individual photo documents in Armenia, Romania, and ungrouped order")
|
||||
@@ -4,7 +4,7 @@ import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
|
||||
photos = sorted(set(re.findall(r'id="photo-([a-f0-9]{64})"', Path('_site/art/index.html').read_text())))
|
||||
photos = sorted(set(re.findall(r'id=["\']photo-([a-f0-9]{64})["\']', Path('_site/art/index.html').read_text())))
|
||||
Path('_site/photo-publication.json').write_text(json.dumps({
|
||||
'commit': os.environ['GITHUB_SHA'], 'photos': photos,
|
||||
'snippets': sorted(set(re.findall(r'id="snippet-([a-f0-9]{64})"',
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
import re
|
||||
import unittest
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
ART = ROOT / "_art"
|
||||
JOB = "7c832afa1b73023d8f2391ff40c221be9ffd468a1a96a6bf4900cbf95595d31d"
|
||||
ARMENIA = [f"/img/arts/uploads/{JOB}/{index:02}.jpg" for index in (9, 8, 7, 6, 5, 4)] + [
|
||||
"/img/arts/uploads/474ab3283ce8801ac6e59b67b65b4169167053873a5a8db4a15b840a3448266c/00.jpg"]
|
||||
ROMANIA = [f"/img/arts/uploads/{JOB}/{index:02}.jpg" for index in (0, 1)] + [
|
||||
f"/img/arts/uploads/c53f20236f166632bff163339c8e789cc09b0d7e63c5b531b1fc20705460975b/{index:02}.jpg"
|
||||
for index in range(5)] + [
|
||||
"/img/arts/uploads/260cc99527c13f256d4ea39d0959f5daa942c888ea882852e73fd94f6c30b7db/00.jpg",
|
||||
"/img/arts/uploads/b18a2f1c7127077c801160782012cb164759f0b9dd41762205b45e4c9a07d673/00.jpg"]
|
||||
|
||||
|
||||
class PhotoHighlightTests(unittest.TestCase):
|
||||
def test_uploaded_photos_are_individual_and_grouped(self):
|
||||
records = []
|
||||
for path in ART.glob("*photo-*.md"):
|
||||
content = path.read_text()
|
||||
images = re.findall(r'<img src="([^"]+/uploads/[^"]+)"', content)
|
||||
self.assertEqual(len(images), 1, path)
|
||||
date = re.search(r'^date: "([^"]+)"', content, re.MULTILINE)
|
||||
anchor = re.search(r'^anchor: "([^"]+)"', content, re.MULTILINE)
|
||||
records.append((datetime.fromisoformat(date.group(1)), images[0],
|
||||
anchor.group(1) if anchor else None, content))
|
||||
records.sort(reverse=True)
|
||||
grouped = [record for record in records if record[1] in ARMENIA + ROMANIA]
|
||||
self.assertEqual([record[1] for record in grouped], ARMENIA + ROMANIA)
|
||||
self.assertEqual(grouped[0][2], "Armenia")
|
||||
self.assertEqual(grouped[7][2], "Romania")
|
||||
self.assertIn("Transmission of Flesh by Erfan Ashourioun", grouped[2][3])
|
||||
|
||||
def test_existing_collection_highlight_starts(self):
|
||||
iran = (ART / "2024-10-25-Taq-e-Bostan_000521270020.md").read_text()
|
||||
kazakhstan = (ART / "2024-10-09-x_DSC-0999.md").read_text()
|
||||
self.assertIn('anchor: "Iran - Hamadan, Kermanshah, Tabriz"', iran)
|
||||
self.assertIn('anchor: "Kazakhstan - World Nomad Games"', kazakhstan)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,37 @@
|
||||
import os
|
||||
import runpy
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
|
||||
class PhotoManifestTest(unittest.TestCase):
|
||||
def test_photo_receipts_accept_single_and_double_quoted_ids(self):
|
||||
first = "a" * 64
|
||||
second = "b" * 64
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
(root / "_site/art").mkdir(parents=True)
|
||||
(root / "_site/snippets").mkdir(parents=True)
|
||||
(root / "_site/art/index.html").write_text(
|
||||
f'<span id="photo-{first}"></span><span id=\'photo-{second}\'></span>'
|
||||
)
|
||||
(root / "_site/snippets/index.html").write_text("")
|
||||
|
||||
with patch("os.environ", {"GITHUB_SHA": "test-commit"}):
|
||||
old_cwd = Path.cwd()
|
||||
try:
|
||||
os.chdir(root)
|
||||
script = Path(__file__).resolve().parents[1] / "photo-manifest.py"
|
||||
runpy.run_path(str(script))
|
||||
finally:
|
||||
os.chdir(old_cwd)
|
||||
|
||||
manifest = (root / "_site/photo-publication.json").read_text()
|
||||
self.assertIn(first, manifest)
|
||||
self.assertIn(second, manifest)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user