From a06a7e8f23bfd64565da4e4141f186180e84a104 Mon Sep 17 00:00:00 2001 From: Dylan Bolger Date: Mon, 17 Aug 2026 16:58:04 -0500 Subject: initial push of photoblog --- app/__init__.py | 0 app/main.py | 12 +++++ app/routers/__init__.py | 0 app/routers/web.py | 9 ++++ app/services/__init__.py | 0 app/services/__pycache__/__init__.cpython-314.pyc | Bin 0 -> 157 bytes app/services/__pycache__/images.cpython-314.pyc | Bin 0 -> 1250 bytes app/services/images.py | 20 ++++++++ app/static/index.css | 55 ++++++++++++++++++++++ app/static/styles.css | 3 ++ app/templates/image.html | 9 ++++ app/templates/index.html | 47 ++++++++++++++++++ 12 files changed, 155 insertions(+) create mode 100644 app/__init__.py create mode 100644 app/main.py create mode 100644 app/routers/__init__.py create mode 100644 app/routers/web.py create mode 100644 app/services/__init__.py create mode 100644 app/services/__pycache__/__init__.cpython-314.pyc create mode 100644 app/services/__pycache__/images.cpython-314.pyc create mode 100644 app/services/images.py create mode 100644 app/static/index.css create mode 100644 app/static/styles.css create mode 100644 app/templates/image.html create mode 100644 app/templates/index.html (limited to 'app') diff --git a/app/__init__.py b/app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/main.py b/app/main.py new file mode 100644 index 0000000..fac1daa --- /dev/null +++ b/app/main.py @@ -0,0 +1,12 @@ +from fastapi import FastAPI +from fastapi.staticfiles import StaticFiles +from fastapi.templating import Jinja2Templates +from .routers import web +from .services import images + +app = FastAPI() +app.state.image_service = images +app.state.templates = Jinja2Templates(directory="./app/templates") +app.include_router(web.router) +app.mount("/static", StaticFiles(directory="./app/static"), name="static") +app.mount("/photos", StaticFiles(directory=images.photos_dir), name="photos") \ No newline at end of file diff --git a/app/routers/__init__.py b/app/routers/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/routers/web.py b/app/routers/web.py new file mode 100644 index 0000000..e97bc42 --- /dev/null +++ b/app/routers/web.py @@ -0,0 +1,9 @@ +from fastapi import APIRouter, Request + +router = APIRouter(prefix="/photos") + +@router.get("/") +async def main_page(request: Request): + images = request.app.state.image_service.get_all_images() + return request.app.state.templates.TemplateResponse( + request=request, name="index.html", context={"images": images}) \ No newline at end of file diff --git a/app/services/__init__.py b/app/services/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/services/__pycache__/__init__.cpython-314.pyc b/app/services/__pycache__/__init__.cpython-314.pyc new file mode 100644 index 0000000..b31d35f Binary files /dev/null and b/app/services/__pycache__/__init__.cpython-314.pyc differ diff --git a/app/services/__pycache__/images.cpython-314.pyc b/app/services/__pycache__/images.cpython-314.pyc new file mode 100644 index 0000000..2514767 Binary files /dev/null and b/app/services/__pycache__/images.cpython-314.pyc differ diff --git a/app/services/images.py b/app/services/images.py new file mode 100644 index 0000000..bd02384 --- /dev/null +++ b/app/services/images.py @@ -0,0 +1,20 @@ +from pathlib import Path +import random + +print(str(Path.cwd())) +root_dir = Path.cwd() +photos_dir = Path(f"{root_dir}/photos") + +image_cache = set() + +def cache_images(): + for file_path in photos_dir.rglob("*"): + if file_path.is_file(): + image_path = file_path.relative_to(root_dir).name + image_cache.add(str(image_path)) + +def get_all_images(): + if not image_cache: + cache_images() + shuffled = random.sample(list(image_cache), k=len(image_cache)) + return shuffled diff --git a/app/static/index.css b/app/static/index.css new file mode 100644 index 0000000..25367be --- /dev/null +++ b/app/static/index.css @@ -0,0 +1,55 @@ +* { + box-sizing: content-box; + font-family: 'Source Code Pro'; +} + +.container { + margin: 0 auto; +} + +header { + text-align: center; + margin-bottom: 3rem; +} + +.gallery { + padding-top: 20px; + column-count: 1; + column-gap: 1.25rem; + width: 100%; +} + +@media (min-width: 640px) { + .gallery { + column-count: 2; + } +} + +@media (min-width: 1024px) { + .gallery { + column-count: 3; + } +} + +@media (min-width: 1280px) { + .gallery { + column-count: 4; + } +} + +.gallery-item { + border-radius: 12px; + overflow: hidden; + margin-bottom: 1.25rem; + break-inside: avoid; + display: inline-block; + width: 100%; + box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05); +} + +.gallery-item img { + display: block; + width: 100%; + height: auto; + object-fit: cover; +} \ No newline at end of file diff --git a/app/static/styles.css b/app/static/styles.css new file mode 100644 index 0000000..8dfb832 --- /dev/null +++ b/app/static/styles.css @@ -0,0 +1,3 @@ +* { + color: red; +} \ No newline at end of file diff --git a/app/templates/image.html b/app/templates/image.html new file mode 100644 index 0000000..c070faf --- /dev/null +++ b/app/templates/image.html @@ -0,0 +1,9 @@ + + + Item Details + + + +

Item ID: {{ id }}

+ + \ No newline at end of file diff --git a/app/templates/index.html b/app/templates/index.html new file mode 100644 index 0000000..991088a --- /dev/null +++ b/app/templates/index.html @@ -0,0 +1,47 @@ + + + + + + + + + + Dylan's Photo Blog + + + + +
+

Photo Blog

+

Here's some pictures I took that I think you would enjoy.

+ {% if images and images|length > 0 %} +
+ {% for img in images %} + + {% endfor %} +
+ {% else %} +

+ If you're reading this, something went wrong and you should send me an email. Thanks! +

+ {% endif %} + + + \ No newline at end of file -- cgit v1.2.3