gallery of photos in the activity page
This commit is contained in:
@@ -8,6 +8,7 @@ from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from fastapi import FastAPI, File, HTTPException, UploadFile
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.responses import HTMLResponse, JSONResponse, RedirectResponse
|
||||
|
||||
# Populated by the CLI before uvicorn starts
|
||||
@@ -16,6 +17,14 @@ site_url: str = "http://localhost:4321"
|
||||
|
||||
app = FastAPI(title="BincioActivity Edit Server", docs_url=None, redoc_url=None)
|
||||
|
||||
# Allow the Astro dev server (and any local origin) to call the write API
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=["*"],
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
SPORTS = ["cycling", "running", "hiking", "walking", "swimming", "skiing", "other"]
|
||||
STAT_PANELS = ["elevation", "speed", "heart_rate", "cadence", "power"]
|
||||
|
||||
|
||||
+26
-7
@@ -90,6 +90,22 @@ def merge_all(data_dir: Path) -> int:
|
||||
for md_path in sorted(edits_dir.glob("*.md")):
|
||||
sidecars[md_path.stem] = parse_sidecar(md_path)
|
||||
|
||||
# Collect image lists — activities with uploaded images get custom.images even
|
||||
# if they have no sidecar text yet
|
||||
image_lists: dict[str, list[str]] = {}
|
||||
images_root = edits_dir / "images" if edits_dir.exists() else None
|
||||
if images_root and images_root.exists():
|
||||
for img_dir in sorted(images_root.iterdir()):
|
||||
if img_dir.is_dir():
|
||||
files = sorted(
|
||||
p.name for p in img_dir.iterdir()
|
||||
if p.is_file() and not p.name.startswith(".")
|
||||
)
|
||||
if files:
|
||||
image_lists[img_dir.name] = files
|
||||
|
||||
to_merge = set(sidecars) | set(image_lists)
|
||||
|
||||
# Wipe and recreate _merged/activities/
|
||||
if merged_acts.exists():
|
||||
shutil.rmtree(merged_acts)
|
||||
@@ -102,20 +118,23 @@ def merge_all(data_dir: Path) -> int:
|
||||
continue
|
||||
dest = merged_acts / src.name
|
||||
activity_id = src.stem
|
||||
if src.suffix == ".json" and activity_id in sidecars:
|
||||
fm, body = sidecars[activity_id]
|
||||
if src.suffix == ".json" and activity_id in to_merge:
|
||||
detail = json.loads(src.read_text(encoding="utf-8"))
|
||||
merged = apply_sidecar(detail, fm, body)
|
||||
dest.write_text(json.dumps(merged, indent=2, ensure_ascii=False))
|
||||
if activity_id in sidecars:
|
||||
fm, body = sidecars[activity_id]
|
||||
detail = apply_sidecar(detail, fm, body)
|
||||
if activity_id in image_lists:
|
||||
detail["custom"] = dict(detail.get("custom") or {})
|
||||
detail["custom"]["images"] = image_lists[activity_id]
|
||||
dest.write_text(json.dumps(detail, indent=2, ensure_ascii=False))
|
||||
else:
|
||||
dest.symlink_to(src.resolve())
|
||||
|
||||
# Mirror edits/images/ → _merged/activities/images/ so the site can serve them
|
||||
edits_images = edits_dir / "images" if edits_dir.exists() else None
|
||||
if edits_images and edits_images.exists():
|
||||
if images_root and images_root.exists():
|
||||
merged_images = merged_acts / "images"
|
||||
merged_images.mkdir(exist_ok=True)
|
||||
for img_dir in edits_images.iterdir():
|
||||
for img_dir in images_root.iterdir():
|
||||
if img_dir.is_dir():
|
||||
dest_img = merged_images / img_dir.name
|
||||
if not dest_img.exists():
|
||||
|
||||
Reference in New Issue
Block a user