summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.dockerignore13
-rw-r--r--.gitignore4
-rw-r--r--Dockerfile13
-rw-r--r--app/__init__.py0
-rw-r--r--app/main.py12
-rw-r--r--app/routers/__init__.py0
-rw-r--r--app/routers/web.py9
-rw-r--r--app/services/__init__.py0
-rw-r--r--app/services/__pycache__/__init__.cpython-314.pycbin0 -> 157 bytes
-rw-r--r--app/services/__pycache__/images.cpython-314.pycbin0 -> 1250 bytes
-rw-r--r--app/services/images.py20
-rw-r--r--app/static/index.css55
-rw-r--r--app/static/styles.css3
-rw-r--r--app/templates/image.html9
-rw-r--r--app/templates/index.html47
-rw-r--r--requirements.txt1
16 files changed, 186 insertions, 0 deletions
diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 0000000..ae9d5d1
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1,13 @@
+**/.git
+**/.gitignore
+**/__pycache__
+**/*.pyc
+**/*.pyo
+**/*.pyd
+**/.pytest_cache
+**/.env
+**/.venv
+venv/
+ENV/
+.aws/
+.vscode/ \ No newline at end of file
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..bdaf325
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+.vscode/
+photos/
+photoblog.db
+/*.html \ No newline at end of file
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..edd88ad
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,13 @@
+FROM python:3.14
+
+WORKDIR /app
+
+COPY requirements.txt .
+
+RUN pip install -r requirements.txt
+
+COPY . .
+
+EXPOSE 80
+
+CMD ["fastapi", "run", "app/main.py", "--port", "80"] \ No newline at end of file
diff --git a/app/__init__.py b/app/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/app/__init__.py
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
--- /dev/null
+++ b/app/routers/__init__.py
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
--- /dev/null
+++ b/app/services/__init__.py
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
--- /dev/null
+++ b/app/services/__pycache__/__init__.cpython-314.pyc
Binary files 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
--- /dev/null
+++ b/app/services/__pycache__/images.cpython-314.pyc
Binary files 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 @@
+<html>
+<head>
+ <title>Item Details</title>
+ <link href="{{ url_for('static', path='/styles.css') }}" rel="stylesheet">
+</head>
+<body>
+ <h1><a href="{{ url_for('read_item', id=id) }}">Item ID: {{ id }}</a></h1>
+</body>
+</html> \ 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 @@
+<!DOCTYPE html>
+<html lang="en">
+
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <link rel="stylesheet" href="https://dbolger.dev/assets/css/main.css">
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/water.css">
+ <link rel="stylesheet" href="{{ url_for('static', path='index.css') }}">
+ <title>Dylan's Photo Blog</title>
+</head>
+
+<body>
+ <nav id="nav" class="topnav">
+ <a class="active" href="https://dbolger.dev">Dylan Bolger</a>
+ <p>Software Engineer</p>
+ <div class="topnav-right">
+ <a href="https://dbolger.dev/#Experience">Experience</a>
+ <a href="https://dbolger.dev/#Projects">Projects</a>
+ <a href="https://blog.dbolger.dev">Blog</a>
+ <a href="https://blog.dbolger.dev">Blog</a>
+ <a href="https://git.dbolger.dev">Git</a>
+ <a href="https://dbolger.dev/assets/pdf/resume.pdf">Resume</a>
+ <a href="mailto:dylan.bolger00@gmail.com">Contact</a>
+ </div>
+ </nav>
+ <section class="container">
+ <h1>Photo Blog</h1>
+ <p>Here's some pictures I took that I think you would enjoy.</p>
+ {% if images and images|length > 0 %}
+ <main class="gallery">
+ {% for img in images %}
+ <div class="gallery-item">
+ <a href="{{ url_for('photos', path=img) }}">
+ <img src="{{ url_for('photos', path=img) }}" alt="" loading="lazy">
+ </a>
+ </div>
+ {% endfor %}
+ </main>
+ {% else %}
+ <p>
+ If you're reading this, something went wrong and you should send me an email. Thanks!
+ </p>
+ {% endif %}
+ </div>
+</body>
+</html> \ No newline at end of file
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 0000000..be08dc6
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1 @@
+fastapi[standard] \ No newline at end of file