🎉 initial commit
This commit is contained in:
95
app.py
Normal file
95
app.py
Normal file
@@ -0,0 +1,95 @@
|
||||
from flask import Flask, render_template, abort
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
# Configuration
|
||||
app.config['SECRET_KEY'] = 'your-secret-key-here' # Change this in production
|
||||
|
||||
# Sample comic data (in production, this would come from a database)
|
||||
COMICS = [
|
||||
{
|
||||
'number': 1,
|
||||
'title': 'First Comic',
|
||||
'filename': 'comic-001.png',
|
||||
'date': '2025-01-01',
|
||||
'alt_text': 'The very first comic',
|
||||
'transcript': 'This is where your comic journey begins!'
|
||||
},
|
||||
{
|
||||
'number': 2,
|
||||
'title': 'Second Comic',
|
||||
'filename': 'comic-002.png',
|
||||
'date': '2025-01-08',
|
||||
'alt_text': 'The second comic',
|
||||
'transcript': 'The adventure continues...'
|
||||
},
|
||||
{
|
||||
'number': 3,
|
||||
'title': 'Third Comic',
|
||||
'filename': 'comic-003.png',
|
||||
'date': '2025-01-15',
|
||||
'alt_text': 'The third comic',
|
||||
'transcript': 'Things are getting interesting!'
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
def get_comic_by_number(number):
|
||||
"""Get a comic by its number"""
|
||||
for comic in COMICS:
|
||||
if comic['number'] == number:
|
||||
return comic
|
||||
return None
|
||||
|
||||
|
||||
def get_latest_comic():
|
||||
"""Get the most recent comic"""
|
||||
if COMICS:
|
||||
return COMICS[-1]
|
||||
return None
|
||||
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
"""Home page - shows latest comic"""
|
||||
comic = get_latest_comic()
|
||||
if not comic:
|
||||
return render_template('index.html', title='Latest Comic',
|
||||
comic=None, total_comics=0)
|
||||
return render_template('index.html', title='Latest Comic',
|
||||
comic=comic, total_comics=len(COMICS))
|
||||
|
||||
|
||||
@app.route('/comic/<int:comic_id>')
|
||||
def comic(comic_id):
|
||||
"""View a specific comic"""
|
||||
comic = get_comic_by_number(comic_id)
|
||||
if not comic:
|
||||
abort(404)
|
||||
return render_template('comic.html', title=f"Comic #{comic_id}",
|
||||
comic=comic, total_comics=len(COMICS))
|
||||
|
||||
|
||||
@app.route('/archive')
|
||||
def archive():
|
||||
"""Archive page showing all comics"""
|
||||
# Reverse order to show newest first
|
||||
comics = list(reversed(COMICS))
|
||||
return render_template('archive.html', title='Archive',
|
||||
comics=comics)
|
||||
|
||||
|
||||
@app.route('/about')
|
||||
def about():
|
||||
"""About page"""
|
||||
return render_template('about.html', title='About')
|
||||
|
||||
|
||||
@app.errorhandler(404)
|
||||
def page_not_found(e):
|
||||
"""404 error handler"""
|
||||
return render_template('404.html', title='Page Not Found'), 404
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True)
|
||||
Reference in New Issue
Block a user