✨ multi-image comics
This commit is contained in:
46
app.py
46
app.py
@@ -3,6 +3,7 @@
|
||||
# Licensed under the MIT License - see LICENSE file for details
|
||||
|
||||
import os
|
||||
import logging
|
||||
from datetime import datetime
|
||||
from flask import Flask, render_template, abort, jsonify, request
|
||||
from comics_data import (
|
||||
@@ -13,6 +14,10 @@ from comics_data import (
|
||||
)
|
||||
import markdown
|
||||
|
||||
# Configure logging
|
||||
logging.basicConfig(level=logging.WARNING)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
# Configuration
|
||||
@@ -117,6 +122,47 @@ def enrich_comic(comic):
|
||||
enriched['plain'] = is_plain(comic)
|
||||
enriched['formatted_date'] = format_comic_date(comic['date'])
|
||||
|
||||
# Normalize filename to list for multi-image support
|
||||
if isinstance(comic.get('filename'), list):
|
||||
enriched['filenames'] = comic['filename']
|
||||
enriched['is_multi_image'] = True
|
||||
else:
|
||||
enriched['filenames'] = [comic['filename']] if 'filename' in comic else []
|
||||
enriched['is_multi_image'] = False
|
||||
|
||||
# Normalize alt_text to list matching filenames
|
||||
if isinstance(comic.get('alt_text'), list):
|
||||
enriched['alt_texts'] = comic['alt_text']
|
||||
|
||||
# Warn if alt_text list doesn't match filenames length
|
||||
if len(enriched['alt_texts']) != len(enriched['filenames']):
|
||||
logger.warning(
|
||||
f"Comic #{comic['number']}: alt_text list length ({len(enriched['alt_texts'])}) "
|
||||
f"doesn't match filenames length ({len(enriched['filenames'])}). "
|
||||
f"Tip: Use a single string for alt_text to apply the same text to all images, "
|
||||
f"or provide a list matching the number of images."
|
||||
)
|
||||
else:
|
||||
# If single alt_text string, use it for all images (this is intentional and valid)
|
||||
alt_text = comic.get('alt_text', '')
|
||||
enriched['alt_texts'] = [alt_text] * len(enriched['filenames'])
|
||||
|
||||
# Ensure alt_texts list matches filenames length (pad with empty strings if too short)
|
||||
while len(enriched['alt_texts']) < len(enriched['filenames']):
|
||||
enriched['alt_texts'].append('')
|
||||
|
||||
# Trim alt_texts if too long (extra ones won't be used anyway)
|
||||
if len(enriched['alt_texts']) > len(enriched['filenames']):
|
||||
enriched['alt_texts'] = enriched['alt_texts'][:len(enriched['filenames'])]
|
||||
|
||||
# Keep original filename and alt_text for backward compatibility (first image)
|
||||
if enriched['filenames']:
|
||||
enriched['filename'] = enriched['filenames'][0]
|
||||
|
||||
# Ensure alt_text is always a string (use first one if it's a list)
|
||||
if enriched['alt_texts']:
|
||||
enriched['alt_text'] = enriched['alt_texts'][0]
|
||||
|
||||
# Check for explicitly specified markdown author note file
|
||||
if 'author_note_md' in comic and comic['author_note_md']:
|
||||
markdown_note = get_author_note_from_file(comic['author_note_md'])
|
||||
|
||||
Reference in New Issue
Block a user