From 62e71cadd089136368543b9a7973cfebcf057810 Mon Sep 17 00:00:00 2001 From: Kumi Date: Wed, 27 Nov 2024 10:18:57 +0100 Subject: [PATCH] fix: Repositions thumbnail generation logic Moves thumbnail generation code block for clarity and reusability. Ensures thumbnails are created before copying assets, adhering to logical order of operations. --- main.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/main.py b/main.py index b13c45e..965c6f4 100644 --- a/main.py +++ b/main.py @@ -115,17 +115,6 @@ def generate_blog_html(posts_per_page=5): front_matter["content"] = html_content front_matter["slug"] = post_dir.name - # Generate thumbnail if image is present - if "image" in front_matter: - original_image = post_dir / front_matter["image"] - thumbnail_image_name = f"thumb_{original_image.name}" - thumbnail_image = ( - output_dir / "blog" / post_dir.name / thumbnail_image_name - ) - create_thumbnail(original_image, thumbnail_image) - - front_matter["thumbnail"] = thumbnail_image_name - # Create excerpt if not present if "excerpt" not in front_matter: excerpt = html_content.split("

")[0] @@ -137,6 +126,17 @@ def generate_blog_html(posts_per_page=5): output_post_dir = output_dir / "blog" / post_dir.name output_post_dir.mkdir(parents=True, exist_ok=True) + # Generate thumbnail if image is present + if "image" in front_matter: + original_image = post_dir / front_matter["image"] + thumbnail_image_name = f"thumb_{original_image.name}" + thumbnail_image = ( + output_dir / "blog" / post_dir.name / thumbnail_image_name + ) + create_thumbnail(original_image, thumbnail_image) + + front_matter["thumbnail"] = thumbnail_image_name + # Copy non-markdown assets copy_assets(post_dir, output_post_dir)