✨ sections
This commit is contained in:
42
app.py
42
app.py
@@ -7,9 +7,9 @@ from datetime import datetime
|
||||
from flask import Flask, render_template, abort, jsonify, request
|
||||
from comics_data import (
|
||||
COMICS, COMIC_NAME, SITE_URL, FULL_WIDTH_DEFAULT, PLAIN_DEFAULT, LOGO_IMAGE, LOGO_MODE,
|
||||
HEADER_IMAGE, FOOTER_IMAGE, COMPACT_FOOTER, ARCHIVE_FULL_WIDTH, USE_COMIC_NAV_ICONS,
|
||||
USE_HEADER_NAV_ICONS, USE_FOOTER_SOCIAL_ICONS, SOCIAL_INSTAGRAM, SOCIAL_YOUTUBE,
|
||||
SOCIAL_EMAIL, API_SPEC_LINK
|
||||
HEADER_IMAGE, FOOTER_IMAGE, COMPACT_FOOTER, ARCHIVE_FULL_WIDTH, SECTIONS_ENABLED,
|
||||
USE_COMIC_NAV_ICONS, USE_HEADER_NAV_ICONS, USE_FOOTER_SOCIAL_ICONS, SOCIAL_INSTAGRAM,
|
||||
SOCIAL_YOUTUBE, SOCIAL_EMAIL, API_SPEC_LINK
|
||||
)
|
||||
import markdown
|
||||
|
||||
@@ -31,6 +31,7 @@ def inject_global_settings():
|
||||
'footer_image': FOOTER_IMAGE,
|
||||
'compact_footer': COMPACT_FOOTER,
|
||||
'archive_full_width': ARCHIVE_FULL_WIDTH,
|
||||
'sections_enabled': SECTIONS_ENABLED,
|
||||
'use_comic_nav_icons': USE_COMIC_NAV_ICONS,
|
||||
'use_header_nav_icons': USE_HEADER_NAV_ICONS,
|
||||
'use_footer_social_icons': USE_FOOTER_SOCIAL_ICONS,
|
||||
@@ -141,13 +142,46 @@ def comic(comic_id):
|
||||
comic=comic, total_comics=len(COMICS))
|
||||
|
||||
|
||||
def group_comics_by_section(comics_list):
|
||||
"""Group comics by section. Returns list of (section_title, comics) tuples"""
|
||||
if not SECTIONS_ENABLED:
|
||||
return [(None, comics_list)]
|
||||
|
||||
sections = []
|
||||
current_section = None
|
||||
current_comics = []
|
||||
|
||||
for comic in comics_list:
|
||||
# Check if this comic starts a new section
|
||||
if 'section' in comic:
|
||||
# Save previous section if it has comics
|
||||
if current_comics:
|
||||
sections.append((current_section, current_comics))
|
||||
# Start new section
|
||||
current_section = comic['section']
|
||||
current_comics = [comic]
|
||||
else:
|
||||
# Add to current section
|
||||
current_comics.append(comic)
|
||||
|
||||
# Don't forget the last section
|
||||
if current_comics:
|
||||
sections.append((current_section, current_comics))
|
||||
|
||||
return sections
|
||||
|
||||
|
||||
@app.route('/archive')
|
||||
def archive():
|
||||
"""Archive page showing all comics"""
|
||||
# Reverse order to show newest first
|
||||
comics = [enrich_comic(comic) for comic in reversed(COMICS)]
|
||||
|
||||
# Group by section if enabled
|
||||
sections = group_comics_by_section(comics)
|
||||
|
||||
return render_template('archive.html', title='Archive',
|
||||
comics=comics)
|
||||
sections=sections)
|
||||
|
||||
|
||||
@app.route('/about')
|
||||
|
||||
Reference in New Issue
Block a user