From 11a3a2d8b275c1ef061ff37caa0a36faf5cce049 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Mon, 2 Jun 2025 13:22:31 +0300 Subject: Add meta frontmatter --- app.py | 19 +++++++++++++++++-- compose.yml | 3 ++- templates/gallery.html | 25 +++++++++++++++++++------ 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/app.py b/app.py index 6f0e7cc..0de55f2 100644 --- a/app.py +++ b/app.py @@ -1,6 +1,7 @@ import os import threading import time +from flask.helpers import url_for import requests import re import sqlite3 @@ -21,8 +22,9 @@ PORT = int(os.environ.get("PORT", 5000)) THUMBNAIL_DIR = "thumbnails" DB_FILE = "data/sqlite.db" ISO_DATE_REGEX = re.compile(r"^\d{4}-\d{2}-\d{2}") -TITLE = os.environ.get("TITLE", "Gallery") +AUTHOR = os.environ["AUTHOR"] IG_LINK = os.environ.get("IG_LINK", None) +BASE_URL = os.environ["BASE_URL"] # Setup os.makedirs(THUMBNAIL_DIR, exist_ok=True) @@ -148,8 +150,21 @@ def gallery(): }) sorted_dates = sorted(grouped.keys(), reverse=True) + + if len(files) > 0: + cover_img_path = url_for("serve_thumbnail", filename=files[0][4].split('/')[-1]) + cover_img_url = BASE_URL + cover_img_path + else: + cover_img_url = None + return render_template("gallery.html", - grouped=grouped, dates=sorted_dates, title=TITLE, ig_link=IG_LINK) + grouped=grouped, + dates=sorted_dates, + author=AUTHOR, + ig_link=IG_LINK, + cover_img_url=cover_img_url, + base_url=BASE_URL, + ) @app.route("/thumbnails/") def serve_thumbnail(filename): diff --git a/compose.yml b/compose.yml index 7480e9b..f8cc5a2 100644 --- a/compose.yml +++ b/compose.yml @@ -7,7 +7,8 @@ services: PYTHONUNBUFFERED: 1 GDRIVE_FOLDER: ${GDRIVE_FOLDER} GAPI_KEY: ${GAPI_KEY} - TITLE: ${TITLE} + AUTHOR: ${AUTHOR} + BASE_URL: ${BASE_URL} volumes: - ./data:/app/data - ./thumbnails:/app/thumbnails diff --git a/templates/gallery.html b/templates/gallery.html index 70f5d25..b5447e2 100644 --- a/templates/gallery.html +++ b/templates/gallery.html @@ -1,14 +1,26 @@ - + - {{ title }} + - - + + + + + + + + - + +

- {{ title }} {% if ig_link %} + {{ author }} {% if ig_link %}