add support for album descriptions

This commit is contained in:
Nick Pegg 2024-08-04 17:22:49 -07:00
parent 03debf05bc
commit 7ae5d8271c
4 changed files with 32 additions and 3 deletions

View file

@ -7,6 +7,7 @@ from typing import Iterator, Optional
from jinja2 import Environment, FileSystemLoader, select_autoescape from jinja2 import Environment, FileSystemLoader, select_autoescape
from PIL import Image, UnidentifiedImageError from PIL import Image, UnidentifiedImageError
from rich.progress import Progress, track from rich.progress import Progress, track
from markdown import markdown
from photojawn.config import Config from photojawn.config import Config
@ -19,6 +20,7 @@ class ImageDirectory:
children: list["ImageDirectory"] children: list["ImageDirectory"]
images: list["ImagePath"] images: list["ImagePath"]
is_root: bool = False is_root: bool = False
description: str = ""
cover_path: Optional["ImagePath"] = None cover_path: Optional["ImagePath"] = None
@ -105,7 +107,11 @@ def find_images(root_path: Path) -> ImageDirectory:
for filename in sorted(filenames): for filename in sorted(filenames):
file_path = dirpath / filename file_path = dirpath / filename
if is_image(file_path): if filename == "description.txt":
image_dir.description = file_path.read_text()
elif filename == "description.md":
image_dir.description = markdown(file_path.read_text())
elif is_image(file_path):
ip = ImagePath(file_path) ip = ImagePath(file_path)
# Set a cover image for the album. Use "cover.jpg" if one exists, # Set a cover image for the album. Use "cover.jpg" if one exists,
@ -154,7 +160,9 @@ def generate_thumbnails(config: Config, root_dir: ImageDirectory) -> None:
thumb_img = orig_img.copy() thumb_img = orig_img.copy()
thumb_img.thumbnail(config.thumbnail_size) thumb_img.thumbnail(config.thumbnail_size)
thumb_img.save(thumb_path) thumb_img.save(thumb_path)
logger.info(f'Generated thumbnail size "{image_path.path}" -> "{thumb_path}"') logger.info(
f'Generated thumbnail size "{image_path.path}" -> "{thumb_path}"'
)
screen_path = image_path.display_path() screen_path = image_path.display_path()
if not screen_path.exists() or not config.quick: if not screen_path.exists() or not config.quick:

View file

@ -12,6 +12,11 @@
{% if not album_dir.is_root %} {% if not album_dir.is_root %}
<h1>{{album_dir.path.name}}</h1> <h1>{{album_dir.path.name}}</h1>
{% endif %} {% endif %}
{% if album_dir.description %}
{{ album_dir.description | safe }}
{% endif %}
{% if album_dir.children %} {% if album_dir.children %}
<div id="album-children"> <div id="album-children">
{% for child in album_dir.children %} {% for child in album_dir.children %}

17
poetry.lock generated
View file

@ -103,6 +103,21 @@ MarkupSafe = ">=2.0"
[package.extras] [package.extras]
i18n = ["Babel (>=2.7)"] i18n = ["Babel (>=2.7)"]
[[package]]
name = "markdown"
version = "3.6"
description = "Python implementation of John Gruber's Markdown."
optional = false
python-versions = ">=3.8"
files = [
{file = "Markdown-3.6-py3-none-any.whl", hash = "sha256:48f276f4d8cfb8ce6527c8f79e2ee29708508bf4d40aa410fbc3b4ee832c850f"},
{file = "Markdown-3.6.tar.gz", hash = "sha256:ed4f41f6daecbeeb96e576ce414c41d2d876daa9a16cb35fa8ed8c2ddfad0224"},
]
[package.extras]
docs = ["mdx-gh-links (>=0.2)", "mkdocs (>=1.5)", "mkdocs-gen-files", "mkdocs-literate-nav", "mkdocs-nature (>=0.6)", "mkdocs-section-index", "mkdocstrings[python]"]
testing = ["coverage", "pyyaml"]
[[package]] [[package]]
name = "markdown-it-py" name = "markdown-it-py"
version = "3.0.0" version = "3.0.0"
@ -565,4 +580,4 @@ files = [
[metadata] [metadata]
lock-version = "2.0" lock-version = "2.0"
python-versions = "^3.12" python-versions = "^3.12"
content-hash = "773580221534dd8152d5385b517f068c9a92fc905eaf7fe0356a97daaa0b7f96" content-hash = "84f4661f5720da5427ac7bcd4e50674ca6017413fdada09d6bd7ea9b8f650818"

View file

@ -17,6 +17,7 @@ jinja2 = "^3.1.4"
pillow = "^10.4.0" pillow = "^10.4.0"
rich = "^13.7.1" rich = "^13.7.1"
pyyaml = "^6.0.1" pyyaml = "^6.0.1"
markdown = "^3.6"
[tool.poetry.group.dev.dependencies] [tool.poetry.group.dev.dependencies]
pytest = "*" pytest = "*"