✨ global option
This commit is contained in:
28
app.py
28
app.py
@@ -1,6 +1,6 @@
|
||||
import os
|
||||
from flask import Flask, render_template, abort, jsonify, request
|
||||
from comics_data import COMICS
|
||||
from comics_data import COMICS, FULL_WIDTH_DEFAULT
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
@@ -8,18 +8,36 @@ app = Flask(__name__)
|
||||
app.config['SECRET_KEY'] = os.environ.get('SECRET_KEY', 'your-secret-key')
|
||||
|
||||
|
||||
def is_full_width(comic):
|
||||
"""Determine if a comic should be full width based on global and per-comic settings"""
|
||||
# If comic explicitly sets full_width, use that value
|
||||
if 'full_width' in comic:
|
||||
return comic['full_width']
|
||||
# Otherwise use the global default
|
||||
return FULL_WIDTH_DEFAULT
|
||||
|
||||
|
||||
def enrich_comic(comic):
|
||||
"""Add computed properties to comic data"""
|
||||
if comic is None:
|
||||
return None
|
||||
enriched = comic.copy()
|
||||
enriched['full_width'] = is_full_width(comic)
|
||||
return enriched
|
||||
|
||||
|
||||
def get_comic_by_number(number):
|
||||
"""Get a comic by its number"""
|
||||
for comic in COMICS:
|
||||
if comic['number'] == number:
|
||||
return comic
|
||||
return enrich_comic(comic)
|
||||
return None
|
||||
|
||||
|
||||
def get_latest_comic():
|
||||
"""Get the most recent comic"""
|
||||
if COMICS:
|
||||
return COMICS[-1]
|
||||
return enrich_comic(COMICS[-1])
|
||||
return None
|
||||
|
||||
|
||||
@@ -48,7 +66,7 @@ def comic(comic_id):
|
||||
def archive():
|
||||
"""Archive page showing all comics"""
|
||||
# Reverse order to show newest first
|
||||
comics = list(reversed(COMICS))
|
||||
comics = [enrich_comic(comic) for comic in reversed(COMICS)]
|
||||
return render_template('archive.html', title='Archive',
|
||||
comics=comics)
|
||||
|
||||
@@ -62,7 +80,7 @@ def about():
|
||||
@app.route('/api/comics')
|
||||
def api_comics():
|
||||
"""API endpoint - returns all comics as JSON"""
|
||||
return jsonify(COMICS)
|
||||
return jsonify([enrich_comic(comic) for comic in COMICS])
|
||||
|
||||
|
||||
@app.route('/api/comics/<int:comic_id>')
|
||||
|
||||
Reference in New Issue
Block a user