4.1 KiB
Photo gallery (dedicated album pages) — design doc
Date: 2026-11-05 Feature: add photo galleries, grouped into albums, viewable on dedicated pages. Approach chosen: A — dedicated album pages (flat albums, single image upload at a time).
Intent / why
Give the site a way to display collections of photos as a grid with a click-to-enlarge lightbox, organized into named groups ("albums"). Reuses the existing image-upload and lightbox infrastructure rather than inventing new storage.
Goals / non-goals
- Goal: upload photos, group them into albums, view an album as a grid on its own page, enlarge via lightbox (Esc / arrows / backdrop).
- Non-goal: cropping/editing photos, geolocation, EXIF metadata, image resizing.
- Anti-goal: don't slow the site or bloat the schema; keep it in the existing Flask + SQLite + plain-template style.
Constraints (found while investigating)
- Images are stored as files in
static/uploads/(on the named volume, so they persist), validated by magic-byte signature at upload time; there is no database table for media today. To group them we must track them in a table (filename + album). - Pages render markdown via
render_markdown(); lightbox reads images bydata-src. - Admin routes use the
@_login_requireddecorator +flash+jsonify; admin templates extendadmin/base.html(nav-menu + sidebar, both driven byactive_page). - Werkzeug 3.1.9 / Flask 3.0.3; dependency-free.
Approach (what you picked)
- A — dedicated album pages (
/photos/<slug>), not embedded-in-page shortcodes. - Flat albums (no hierarchy).
- Single image upload at a time (matches your current
/uploadhandler).
Rejected: embedded markdown shortcodes (option B) — would force every page author to know a new syntax; dedicated pages are cleaner URLs and share the existing lightbox. Nested albums and batch upload were rejected as scope creep for v1.
The parts (builder's plan)
Data model (two new tables, appended in db.py init_db()):
media_albums(id, name, slug UNIQUE, description, created_at)— the groups.media(id, filename, url, album_id FK→media_albums, position, created_at)— individual photos.
Admin (blog/admin.py):
- Album CRUD:
/admin/albums(list),/admin/albums/new,/admin/albums/<slug>/edit,/admin/albums/<slug>/delete. - Media management:
/admin/medialists all photos grouped by album; ungrouped photos shown under "(none)". Per-photo actions:- Assign to album — dropdown to move a photo into an album (add).
- Remove from album — uncouple (
album_id = NULL, keep file). This is the only default delete; it never removes the file.
- Extend the existing
/uploadhandler to create amediarow and offer album selection in the response (album = null allowed, so photos can be ungrouped). - Add nav links (nav-menu + sidebar) for Albums / Media, driven by
active_page.
Public (blog/public.py):
- Route
/photos/<slug>→ render the album's media grid._album_by_slug(slug)helper; unknown slug → 404.
Templates:
- New
templates/photos.html— responsive grid, each<img data-src=...>so the existinglightbox.jshandles enlarge for free. Empty album / no-media states handled. - New
templates/admin/albums.html,templates/admin/media.html, and an album edit form. - Reuse
admin/base.html(no new shell).
Decisions left to builder (my calls, unless you object)
- Album slug auto-generated from name; editable.
positioninteger for manual ordering within an album; reordering via a simple up/down or drag-free renumber.- Delete album → UNCUPLE, not delete.
UPDATE media SET album_id = NULL WHERE album_id = ?. Photos stay in/uploadsand become ungrouped; nothing is deleted. - Gallery layout: responsive CSS grid, masonry-ish via
aspect-ratioto avoid layout shift.
Left to builder
Implement above, then verify with a test client: upload → assign album → view /photos/<slug>
grid → lightbox open/close; delete album uncouples photos (album_id=NULL, files kept); assign/
remove-from-album re-groups correctly; unknown album 404s.