From 0eccc4b12efa502d01269c216b6c7af15fbf0211 Mon Sep 17 00:00:00 2001 From: mi Date: Sat, 15 Nov 2025 14:55:55 +1000 Subject: [PATCH] :mag: robots and other optimizations --- app.py | 17 +++++++++++++++++ templates/archive.html | 3 ++- templates/base.html | 1 + templates/comic.html | 27 +++++++++++++++++++++++++-- 4 files changed, 45 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index bdac6e8..cb58073 100644 --- a/app.py +++ b/app.py @@ -239,6 +239,23 @@ def sitemap(): return send_from_directory('static', 'sitemap.xml', mimetype='application/xml') +@app.route('/robots.txt') +def robots(): + """Generate robots.txt dynamically with correct SITE_URL""" + from flask import Response + robots_txt = f"""# Sunday Comics - Robots.txt +User-agent: * +Allow: / + +# Sitemap location +Sitemap: {SITE_URL}/sitemap.xml + +# Disallow API endpoints from indexing +Disallow: /api/ +""" + return Response(robots_txt, mimetype='text/plain') + + @app.errorhandler(404) def page_not_found(e): """404 error handler""" diff --git a/templates/archive.html b/templates/archive.html index a583bff..f14d5f5 100644 --- a/templates/archive.html +++ b/templates/archive.html @@ -24,7 +24,8 @@ {{ comic.title if comic.title else '#' ~ comic.number }} + alt="{{ comic.title if comic.title else '#' ~ comic.number }}" + loading="lazy">
{% if not archive_full_width %}

#{{ comic.number }}{% if comic.title %}: {{ comic.title }}{% endif %}

diff --git a/templates/base.html b/templates/base.html index 9d4e367..5ca7854 100644 --- a/templates/base.html +++ b/templates/base.html @@ -7,6 +7,7 @@ + diff --git a/templates/comic.html b/templates/comic.html index ea5b8c3..83dc7fb 100644 --- a/templates/comic.html +++ b/templates/comic.html @@ -4,6 +4,27 @@ {% block og_image %}{{ site_url }}/static/images/thumbs/{{ comic.filename }}{% endblock %} +{% block extra_css %} + +{% endblock %} + {% block content %}
@@ -29,7 +50,8 @@ {% else %} {{ comic.title if comic.title else '#' ~ comic.number }} + title="{{ comic.alt_text }}" + loading="eager"> {% endif %}
{% else %} @@ -43,7 +65,8 @@ {% else %} {{ comic.title if comic.title else '#' ~ comic.number }} + title="{{ comic.alt_text }}" + loading="eager"> {% endif %} {% endif %}