From 9fa42df385074740bb3a568709c0ada1048c087b Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Sun, 30 Apr 2023 00:53:55 +0100 Subject: [PATCH] Improve description tag generation --- app/template_filters.py | 19 +++++++++++++++++-- app/templates/base.html | 12 ++++++++---- app/templates/donate/index.html | 6 ------ app/templates/index.html | 4 ++++ app/templates/packages/game_hub.html | 7 +++---- app/templates/packages/gone.html | 14 +++++++------- app/templates/packages/view.html | 14 +++++++------- app/templates/threads/view.html | 8 ++++---- 8 files changed, 50 insertions(+), 34 deletions(-) diff --git a/app/template_filters.py b/app/template_filters.py index 333eeb22..0442f532 100644 --- a/app/template_filters.py +++ b/app/template_filters.py @@ -1,24 +1,27 @@ from . import app, utils from .models import Permission, Package, PackageState, PackageRelease from .utils import abs_url_for, url_set_query, url_set_anchor, url_current +from .utils.minetest_hypertext import normalize_whitespace as do_normalize_whitespace +from .markdown import get_headings + from flask_login import current_user from flask_babel import format_timedelta, gettext from urllib.parse import urlparse from datetime import datetime as dt -from app.markdown import get_headings - @app.context_processor def inject_debug(): return dict(debug=app.debug) + @app.context_processor def inject_functions(): check_global_perm = Permission.checkPerm return dict(abs_url_for=abs_url_for, url_set_query=url_set_query, url_set_anchor=url_set_anchor, check_global_perm=check_global_perm, get_headings=get_headings, url_current=url_current) + @app.context_processor def inject_todo(): todo_list_count = None @@ -28,14 +31,22 @@ def inject_todo(): return dict(todo_list_count=todo_list_count) + @app.template_filter() def throw(err): raise Exception(err) + +@app.template_filter() +def normalize_whitespace(str): + return do_normalize_whitespace(str).strip() + + @app.template_filter() def domain(url): return urlparse(url).netloc + @app.template_filter() def date(value): return value.strftime("%Y-%m-%d") @@ -45,6 +56,7 @@ def date(value): def full_datetime(value): return value.strftime("%Y-%m-%d %H:%M") + " UTC" + @app.template_filter() def datetime(value): delta = dt.utcnow() - value @@ -53,14 +65,17 @@ def datetime(value): else: return full_datetime(value) + @app.template_filter() def isodate(value): return value.strftime("%Y-%m-%d") + @app.template_filter() def timedelta(value): return format_timedelta(value) + @app.template_filter() def abs_url(url): return utils.abs_url(url) diff --git a/app/templates/base.html b/app/templates/base.html index 1bc340fe..c965c87c 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -4,16 +4,20 @@ - {% block title %}title{% endblock %} - {{ config.USER_APP_NAME }} + {{ self.title() | normalize_whitespace }} - {{ config.USER_APP_NAME }} - {% if noindex %} - - {% endif %} + {% if noindex -%} + + {%- endif %} + {% if self.description -%} + + + {%- endif %} {% block headextra %}{% endblock %} diff --git a/app/templates/donate/index.html b/app/templates/donate/index.html index d8688656..ac76c6c4 100644 --- a/app/templates/donate/index.html +++ b/app/templates/donate/index.html @@ -9,12 +9,6 @@ {{ _("Donations are a great way to support your favorite modders, artists, and game developers.") }} {% endblock %} -{% block headextra %} - - - -{% endblock %} - {% macro authorlink(author) %} {{ author.display_name }} diff --git a/app/templates/index.html b/app/templates/index.html index 239608f6..19e852fc 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -4,6 +4,10 @@ {{ _("Welcome") }} {% endblock %} +{% block description %} +{{ _("Welcome to the best place to find Minetest mods, games, and texture packs") }} +{% endblock %} + {% block scriptextra %}