fix: Repositions thumbnail generation logic
All checks were successful
Build and Deploy Static Site / build (push) Successful in 2m0s

Moves thumbnail generation code block for clarity and reusability.
Ensures thumbnails are created before copying assets, adhering
to logical order of operations.
This commit is contained in:
Kumi 2024-11-27 10:18:57 +01:00
parent 32ddb8df24
commit 62e71cadd0
Signed by: kumi
GPG key ID: ECBCC9082395383F

22
main.py
View file

@ -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("</p>")[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)