🎨 make the markdown file configuration explicit
This commit is contained in:
33
app.py
33
app.py
@@ -72,9 +72,20 @@ def format_comic_date(date_str):
|
||||
return date_str
|
||||
|
||||
|
||||
def get_author_note(date_str):
|
||||
"""Load author note from markdown file if it exists, using date as filename"""
|
||||
note_path = os.path.join(os.path.dirname(__file__), 'content', 'author_notes', f'{date_str}.md')
|
||||
def get_author_note_from_file(filename):
|
||||
"""Load author note from markdown file if it exists
|
||||
|
||||
Args:
|
||||
filename: Either just a filename (looked up in content/author_notes/)
|
||||
or a path relative to content/
|
||||
"""
|
||||
# If filename contains a path separator, treat as relative to content/
|
||||
if '/' in filename or '\\' in filename:
|
||||
note_path = os.path.join(os.path.dirname(__file__), 'content', filename)
|
||||
else:
|
||||
# Just a filename, look in author_notes directory
|
||||
note_path = os.path.join(os.path.dirname(__file__), 'content', 'author_notes', filename)
|
||||
|
||||
try:
|
||||
with open(note_path, 'r', encoding='utf-8') as f:
|
||||
content = f.read()
|
||||
@@ -92,13 +103,17 @@ def enrich_comic(comic):
|
||||
enriched['plain'] = is_plain(comic)
|
||||
enriched['formatted_date'] = format_comic_date(comic['date'])
|
||||
|
||||
# Check for markdown author note, fall back to data field if not found
|
||||
markdown_note = get_author_note(comic['date'])
|
||||
if markdown_note:
|
||||
enriched['author_note'] = markdown_note
|
||||
enriched['author_note_is_html'] = True
|
||||
# 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'])
|
||||
if markdown_note:
|
||||
enriched['author_note'] = markdown_note
|
||||
enriched['author_note_is_html'] = True
|
||||
else:
|
||||
# File specified but not found, use plain text from comic data if it exists
|
||||
enriched['author_note_is_html'] = False
|
||||
else:
|
||||
# No markdown file, use plain text from comic data if it exists
|
||||
# No markdown file specified, use plain text from comic data if it exists
|
||||
enriched['author_note_is_html'] = False
|
||||
|
||||
return enriched
|
||||
|
||||
Reference in New Issue
Block a user