Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ test_scripts/test_pick_from_image.py
icloudpd
scripts/*
!scripts/build_vocab.py
!scripts/download-vendor.py

# Cache directories for mkdocs etc
site
Expand Down
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ help:
@echo "backend-lint Run Python backend linting with Ruff."
@echo "frontend-lint Run JavaScript frontend linting with ESLint and Prettier."
@echo "lint Run both backend and frontend linting."
@echo "vendor Download/copy vendor JS/CSS assets for offline use."

# Run the unit tests
test:
Expand Down Expand Up @@ -122,3 +123,10 @@ frontend-lint:
# Run both backend and frontend linting
.PHONY: lint
lint: backend-lint frontend-lint

# Download vendor JS/CSS assets into static/vendor/ for offline use.
# Commit the generated files so they are bundled with the pip package.
.PHONY: vendor
vendor:
python scripts/download-vendor.py
@echo "Vendor assets ready in photomap/frontend/static/vendor/"
14 changes: 14 additions & 0 deletions photomap/backend/photomap_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,20 @@ async def dispatch(self, request: Request, call_next):
# references pick up the cache-busting version segment automatically.
templates.env.globals["static_url"] = lambda path: f"static/{asset_version}/{path}"

_REQUIRED_VENDOR_FILES = [
"vendor/swiper-bundle.min.js",
"vendor/swiper-bundle.min.css",
"vendor/plotly.min.js",
]
_missing_vendor = [f for f in _REQUIRED_VENDOR_FILES if not (Path(static_path) / f).exists()]
if _missing_vendor:
logger.error(
"Missing vendor files in static/vendor/: %s. "
"Run `python scripts/download-vendor.py` (or `make vendor`) from the repo root "
"to download them, then restart the server.",
", ".join(_missing_vendor),
)


# Main Routes
@app.get("/", response_class=HTMLResponse, tags=["Main"])
Expand Down
3,879 changes: 3,879 additions & 0 deletions photomap/frontend/static/vendor/plotly.min.js

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions photomap/frontend/static/vendor/swiper-bundle.min.css

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions photomap/frontend/static/vendor/swiper-bundle.min.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions photomap/frontend/templates/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
}());
</script>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.css" />
<script src="https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.js"></script>
<script src="https://cdn.plot.ly/plotly-3.0.1.min.js" charset="utf-8"></script>
<link rel="stylesheet" type="text/css" href="{{ static_url('vendor/swiper-bundle.min.css') }}" />
<script src="{{ static_url('vendor/swiper-bundle.min.js') }}"></script>
<script src="{{ static_url('vendor/plotly.min.js') }}" charset="utf-8"></script>
<link rel="stylesheet" type="text/css" href="{{ static_url('css/base.css') }}" />
<link rel="stylesheet" type="text/css" href="{{ static_url('css/animations.css') }}" />
<link rel="stylesheet" type="text/css" href="{{ static_url('css/modal-base.css') }}" />
Expand Down
45 changes: 45 additions & 0 deletions scripts/download-vendor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env python3
"""Download vendor JS/CSS files for offline use.

Run this script once to populate photomap/frontend/static/vendor/ with the
bundled versions of Swiper and Plotly. After running, commit the generated
files so the app works without an internet connection.

Usage:
python scripts/download-vendor.py
"""

import urllib.request
from pathlib import Path

VENDOR_DIR = Path(__file__).parent.parent / "photomap" / "frontend" / "static" / "vendor"

VENDOR_FILES = [
(
"https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.css",
"swiper-bundle.min.css",
),
(
"https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.js",
"swiper-bundle.min.js",
),
(
"https://cdn.plot.ly/plotly-3.0.1.min.js",
"plotly.min.js",
),
]


def main() -> None:
VENDOR_DIR.mkdir(parents=True, exist_ok=True)
for url, filename in VENDOR_FILES:
dest = VENDOR_DIR / filename
print(f"Downloading {filename} ...", end=" ", flush=True)
urllib.request.urlretrieve(url, dest)
size_kb = dest.stat().st_size / 1024
print(f"{size_kb:.1f} KB")
print("Done — vendor assets ready.")


if __name__ == "__main__":
main()
Loading