Improve description tag generation

This commit is contained in:
rubenwardy 2023-04-30 00:53:55 +01:00
parent c2ab4ac308
commit 9fa42df385
8 changed files with 50 additions and 34 deletions

@ -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)

@ -4,16 +4,20 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{% block title %}title{% endblock %} - {{ config.USER_APP_NAME }}</title>
<title>{{ self.title() | normalize_whitespace }} - {{ config.USER_APP_NAME }}</title>
<link rel="stylesheet" type="text/css" href="/static/libs/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="/static/custom.css?v=38">
<link rel="search" type="application/opensearchdescription+xml" href="/static/opensearch.xml" title="ContentDB" />
<link rel="shortcut icon" href="/favicon-16.png" sizes="16x16">
<link rel="icon" href="/favicon-128.png" sizes="128x128">
<link rel="icon" href="/favicon-32.png" sizes="32x32">
{% if noindex %}
<meta name="robots" content="noindex">
{% endif %}
{% if noindex -%}
<meta name="robots" content="noindex">
{%- endif %}
{% if self.description -%}
<meta name="description" content="{{ self.description() | normalize_whitespace }}">
<meta name="og:description" content="{{ self.description() | normalize_whitespace }}">
{%- endif %}
{% block headextra %}{% endblock %}
</head>
<body>

@ -9,12 +9,6 @@
{{ _("Donations are a great way to support your favorite modders, artists, and game developers.") }}
{% endblock %}
{% block headextra %}
<meta name="og:title" content="{{ self.title() }}">
<meta name="og:description" content="{{ self.description() | replace('\n', ' ') }}">
<meta name="description" content="{{ self.description() | replace('\n', ' ') }}">
{% endblock %}
{% macro authorlink(author) %}
<a href="{{ url_for('users.profile', username=author.username) }}">
{{ author.display_name }}

@ -4,6 +4,10 @@
{{ _("Welcome") }}
{% endblock %}
{% block description %}
{{ _("Welcome to the best place to find Minetest mods, games, and texture packs") }}
{% endblock %}
{% block scriptextra %}
<script type="application/ld+json">
{

@ -5,12 +5,11 @@
{{ _('%(title)s by %(author)s', title=package.title, author=package.author.display_name) }}
{% endblock %}
{% block description -%}
{{ _('Mods and texture packs for %(title)s', title=package.title) }}
{% endblock %}
{% block headextra %}
<meta name="og:title" content="{{ self.title() }}"/>
<meta name="og:description" content="{{ _('Mods for %(title)s', title=package.title) }}"/>
<meta name="description" content="{{ _('Mods for %(title)s', title=package.title) }}"/>
<meta name="og:url" content="{{ package.getURL('packages.game_hub', absolute=True) }}"/>
{% if package.getThumbnailURL(3, True) %}
<meta name="og:image" content="{{ package.getThumbnailURL(3, True) }}"/>
{% endif %}

@ -4,14 +4,14 @@
{{ package.title }}
{% endblock %}
{% block description -%}
{{ package.short_desc }}
{% endblock %}
{% block headextra %}
<meta name="og:title" content="{{ package.title }}"/>
<meta name="og:description" content="{{ package.short_desc }}"/>
<meta name="description" content="{{ package.short_desc }}"/>
<meta name="og:url" content="{{ package.getURL("packages.view", absolute=True) }}"/>
{% if package.getThumbnailURL(3, True) %}
<meta name="og:image" content="{{ package.getThumbnailURL(3, True) }}"/>
{% endif %}
{% if package.getThumbnailURL(3, True) -%}
<meta name="og:image" content="{{ package.getThumbnailURL(3, True) }}"/>
{%- endif %}
{% endblock %}
{% block content %}

@ -7,14 +7,14 @@
{{ package.title }}
{% endblock %}
{% block description -%}
{{ package.short_desc }}
{% endblock %}
{% block headextra %}
<meta name="og:title" content="{{ package.title }}"/>
<meta name="og:description" content="{{ package.short_desc }}"/>
<meta name="description" content="{{ package.short_desc }}"/>
<meta name="og:url" content="{{ package.getURL("packages.view", absolute=True) }}"/>
{% if package.getThumbnailURL(3, True) %}
<meta name="og:image" content="{{ package.getThumbnailURL(3, True) }}"/>
{% endif %}
{% if package.getThumbnailURL(3, True) -%}
<meta name="og:image" content="{{ package.getThumbnailURL(3, True) }}"/>
{%- endif %}
{% endblock %}
{% block scriptextra %}

@ -17,11 +17,11 @@
{%- endif -%}
{% endblock %}
{% block description -%}
{{ thread.get_description() }}
{%- endblock %}
{% block headextra %}
<meta name="og:title" content="{{ self.title() }}"/>
<meta name="og:description" content="{{ thread.get_description() }}"/>
<meta name="description" content="{{ thread.get_description() }}"/>
<meta name="og:url" content="{{ thread.getViewURL(absolute=True) }}"/>
<meta name="og:image" content="{{ thread.author.getProfilePicURL() }}"/>
{% endblock %}