date on all pages

This commit is contained in:
mi
2025-11-07 18:55:15 +10:00
parent 234d78d862
commit ed0a1aadb2
4 changed files with 32 additions and 16 deletions

14
app.py
View File

@@ -1,4 +1,5 @@
import os
from datetime import datetime
from flask import Flask, render_template, abort, jsonify, request
from comics_data import COMICS, FULL_WIDTH_DEFAULT, PLAIN_DEFAULT
@@ -26,6 +27,18 @@ def is_plain(comic):
return PLAIN_DEFAULT
def format_comic_date(date_str):
"""Format date string (YYYY-MM-DD) to 'Day name, Month name day, year'"""
try:
date_obj = datetime.strptime(date_str, '%Y-%m-%d')
# Use %d and strip leading zero for cross-platform compatibility
day = date_obj.strftime('%d').lstrip('0')
formatted = date_obj.strftime(f'%A, %B {day}, %Y')
return formatted
except:
return date_str
def enrich_comic(comic):
"""Add computed properties to comic data"""
if comic is None:
@@ -33,6 +46,7 @@ def enrich_comic(comic):
enriched = comic.copy()
enriched['full_width'] = is_full_width(comic)
enriched['plain'] = is_plain(comic)
enriched['formatted_date'] = format_comic_date(comic['date'])
return enriched