✨ global option
This commit is contained in:
28
app.py
28
app.py
@@ -1,6 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
from flask import Flask, render_template, abort, jsonify, request
|
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__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
@@ -8,18 +8,36 @@ app = Flask(__name__)
|
|||||||
app.config['SECRET_KEY'] = os.environ.get('SECRET_KEY', 'your-secret-key')
|
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):
|
def get_comic_by_number(number):
|
||||||
"""Get a comic by its number"""
|
"""Get a comic by its number"""
|
||||||
for comic in COMICS:
|
for comic in COMICS:
|
||||||
if comic['number'] == number:
|
if comic['number'] == number:
|
||||||
return comic
|
return enrich_comic(comic)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get_latest_comic():
|
def get_latest_comic():
|
||||||
"""Get the most recent comic"""
|
"""Get the most recent comic"""
|
||||||
if COMICS:
|
if COMICS:
|
||||||
return COMICS[-1]
|
return enrich_comic(COMICS[-1])
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
@@ -48,7 +66,7 @@ def comic(comic_id):
|
|||||||
def archive():
|
def archive():
|
||||||
"""Archive page showing all comics"""
|
"""Archive page showing all comics"""
|
||||||
# Reverse order to show newest first
|
# 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',
|
return render_template('archive.html', title='Archive',
|
||||||
comics=comics)
|
comics=comics)
|
||||||
|
|
||||||
@@ -62,7 +80,7 @@ def about():
|
|||||||
@app.route('/api/comics')
|
@app.route('/api/comics')
|
||||||
def api_comics():
|
def api_comics():
|
||||||
"""API endpoint - returns all comics as JSON"""
|
"""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>')
|
@app.route('/api/comics/<int:comic_id>')
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
# Comic data
|
# Comic data
|
||||||
# Edit this file to add, remove, or modify comics
|
# Edit this file to add, remove, or modify comics
|
||||||
|
|
||||||
|
# Global setting: Set to True to make all comics full-width by default
|
||||||
|
# Individual comics can override this with 'full_width': False
|
||||||
|
FULL_WIDTH_DEFAULT = False
|
||||||
|
|
||||||
COMICS = [
|
COMICS = [
|
||||||
{
|
{
|
||||||
'number': 1,
|
'number': 1,
|
||||||
@@ -9,14 +13,14 @@ COMICS = [
|
|||||||
'date': '2025-01-01',
|
'date': '2025-01-01',
|
||||||
'alt_text': 'The very first comic',
|
'alt_text': 'The very first comic',
|
||||||
'author_note': 'This is where your comic journey begins!',
|
'author_note': 'This is where your comic journey begins!',
|
||||||
'full_width': True # Optional: removes border and expands image width
|
'full_width': True # Optional: override FULL_WIDTH_DEFAULT for this comic
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'number': 2,
|
'number': 2,
|
||||||
'filename': 'comic-002.jpg',
|
'filename': 'comic-002.jpg',
|
||||||
'date': '2025-01-08',
|
'date': '2025-01-08',
|
||||||
'alt_text': 'The second comic',
|
'alt_text': 'The second comic',
|
||||||
'full_width': True
|
'full_width': True # Override FULL_WIDTH_DEFAULT
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'number': 3,
|
'number': 3,
|
||||||
|
|||||||
Reference in New Issue
Block a user