mirror of
https://github.com/minetest/contentdb.git
synced 2024-12-22 14:02:24 +01:00
Improve description tag generation
This commit is contained in:
parent
c2ab4ac308
commit
9fa42df385
@ -1,24 +1,27 @@
|
|||||||
from . import app, utils
|
from . import app, utils
|
||||||
from .models import Permission, Package, PackageState, PackageRelease
|
from .models import Permission, Package, PackageState, PackageRelease
|
||||||
from .utils import abs_url_for, url_set_query, url_set_anchor, url_current
|
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_login import current_user
|
||||||
from flask_babel import format_timedelta, gettext
|
from flask_babel import format_timedelta, gettext
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
from datetime import datetime as dt
|
from datetime import datetime as dt
|
||||||
|
|
||||||
from app.markdown import get_headings
|
|
||||||
|
|
||||||
|
|
||||||
@app.context_processor
|
@app.context_processor
|
||||||
def inject_debug():
|
def inject_debug():
|
||||||
return dict(debug=app.debug)
|
return dict(debug=app.debug)
|
||||||
|
|
||||||
|
|
||||||
@app.context_processor
|
@app.context_processor
|
||||||
def inject_functions():
|
def inject_functions():
|
||||||
check_global_perm = Permission.checkPerm
|
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,
|
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)
|
check_global_perm=check_global_perm, get_headings=get_headings, url_current=url_current)
|
||||||
|
|
||||||
|
|
||||||
@app.context_processor
|
@app.context_processor
|
||||||
def inject_todo():
|
def inject_todo():
|
||||||
todo_list_count = None
|
todo_list_count = None
|
||||||
@ -28,14 +31,22 @@ def inject_todo():
|
|||||||
|
|
||||||
return dict(todo_list_count=todo_list_count)
|
return dict(todo_list_count=todo_list_count)
|
||||||
|
|
||||||
|
|
||||||
@app.template_filter()
|
@app.template_filter()
|
||||||
def throw(err):
|
def throw(err):
|
||||||
raise Exception(err)
|
raise Exception(err)
|
||||||
|
|
||||||
|
|
||||||
|
@app.template_filter()
|
||||||
|
def normalize_whitespace(str):
|
||||||
|
return do_normalize_whitespace(str).strip()
|
||||||
|
|
||||||
|
|
||||||
@app.template_filter()
|
@app.template_filter()
|
||||||
def domain(url):
|
def domain(url):
|
||||||
return urlparse(url).netloc
|
return urlparse(url).netloc
|
||||||
|
|
||||||
|
|
||||||
@app.template_filter()
|
@app.template_filter()
|
||||||
def date(value):
|
def date(value):
|
||||||
return value.strftime("%Y-%m-%d")
|
return value.strftime("%Y-%m-%d")
|
||||||
@ -45,6 +56,7 @@ def date(value):
|
|||||||
def full_datetime(value):
|
def full_datetime(value):
|
||||||
return value.strftime("%Y-%m-%d %H:%M") + " UTC"
|
return value.strftime("%Y-%m-%d %H:%M") + " UTC"
|
||||||
|
|
||||||
|
|
||||||
@app.template_filter()
|
@app.template_filter()
|
||||||
def datetime(value):
|
def datetime(value):
|
||||||
delta = dt.utcnow() - value
|
delta = dt.utcnow() - value
|
||||||
@ -53,14 +65,17 @@ def datetime(value):
|
|||||||
else:
|
else:
|
||||||
return full_datetime(value)
|
return full_datetime(value)
|
||||||
|
|
||||||
|
|
||||||
@app.template_filter()
|
@app.template_filter()
|
||||||
def isodate(value):
|
def isodate(value):
|
||||||
return value.strftime("%Y-%m-%d")
|
return value.strftime("%Y-%m-%d")
|
||||||
|
|
||||||
|
|
||||||
@app.template_filter()
|
@app.template_filter()
|
||||||
def timedelta(value):
|
def timedelta(value):
|
||||||
return format_timedelta(value)
|
return format_timedelta(value)
|
||||||
|
|
||||||
|
|
||||||
@app.template_filter()
|
@app.template_filter()
|
||||||
def abs_url(url):
|
def abs_url(url):
|
||||||
return utils.abs_url(url)
|
return utils.abs_url(url)
|
||||||
|
@ -4,16 +4,20 @@
|
|||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<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/libs/bootstrap.min.css">
|
||||||
<link rel="stylesheet" type="text/css" href="/static/custom.css?v=38">
|
<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="search" type="application/opensearchdescription+xml" href="/static/opensearch.xml" title="ContentDB" />
|
||||||
<link rel="shortcut icon" href="/favicon-16.png" sizes="16x16">
|
<link rel="shortcut icon" href="/favicon-16.png" sizes="16x16">
|
||||||
<link rel="icon" href="/favicon-128.png" sizes="128x128">
|
<link rel="icon" href="/favicon-128.png" sizes="128x128">
|
||||||
<link rel="icon" href="/favicon-32.png" sizes="32x32">
|
<link rel="icon" href="/favicon-32.png" sizes="32x32">
|
||||||
{% if noindex %}
|
{% if noindex -%}
|
||||||
<meta name="robots" content="noindex">
|
<meta name="robots" content="noindex">
|
||||||
{% endif %}
|
{%- 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 %}
|
{% block headextra %}{% endblock %}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
@ -9,12 +9,6 @@
|
|||||||
{{ _("Donations are a great way to support your favorite modders, artists, and game developers.") }}
|
{{ _("Donations are a great way to support your favorite modders, artists, and game developers.") }}
|
||||||
{% endblock %}
|
{% 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) %}
|
{% macro authorlink(author) %}
|
||||||
<a href="{{ url_for('users.profile', username=author.username) }}">
|
<a href="{{ url_for('users.profile', username=author.username) }}">
|
||||||
{{ author.display_name }}
|
{{ author.display_name }}
|
||||||
|
@ -4,6 +4,10 @@
|
|||||||
{{ _("Welcome") }}
|
{{ _("Welcome") }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block description %}
|
||||||
|
{{ _("Welcome to the best place to find Minetest mods, games, and texture packs") }}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
{% block scriptextra %}
|
{% block scriptextra %}
|
||||||
<script type="application/ld+json">
|
<script type="application/ld+json">
|
||||||
{
|
{
|
||||||
|
@ -5,12 +5,11 @@
|
|||||||
{{ _('%(title)s by %(author)s', title=package.title, author=package.author.display_name) }}
|
{{ _('%(title)s by %(author)s', title=package.title, author=package.author.display_name) }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block description -%}
|
||||||
|
{{ _('Mods and texture packs for %(title)s', title=package.title) }}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
{% block headextra %}
|
{% 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) %}
|
{% if package.getThumbnailURL(3, True) %}
|
||||||
<meta name="og:image" content="{{ package.getThumbnailURL(3, True) }}"/>
|
<meta name="og:image" content="{{ package.getThumbnailURL(3, True) }}"/>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -4,14 +4,14 @@
|
|||||||
{{ package.title }}
|
{{ package.title }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block description -%}
|
||||||
|
{{ package.short_desc }}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
{% block headextra %}
|
{% block headextra %}
|
||||||
<meta name="og:title" content="{{ package.title }}"/>
|
{% if package.getThumbnailURL(3, True) -%}
|
||||||
<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) }}"/>
|
<meta name="og:image" content="{{ package.getThumbnailURL(3, True) }}"/>
|
||||||
{% endif %}
|
{%- endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
@ -7,14 +7,14 @@
|
|||||||
{{ package.title }}
|
{{ package.title }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block description -%}
|
||||||
|
{{ package.short_desc }}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
{% block headextra %}
|
{% block headextra %}
|
||||||
<meta name="og:title" content="{{ package.title }}"/>
|
{% if package.getThumbnailURL(3, True) -%}
|
||||||
<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) }}"/>
|
<meta name="og:image" content="{{ package.getThumbnailURL(3, True) }}"/>
|
||||||
{% endif %}
|
{%- endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block scriptextra %}
|
{% block scriptextra %}
|
||||||
|
@ -17,11 +17,11 @@
|
|||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block description -%}
|
||||||
|
{{ thread.get_description() }}
|
||||||
|
{%- endblock %}
|
||||||
|
|
||||||
{% block headextra %}
|
{% 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() }}"/>
|
<meta name="og:image" content="{{ thread.author.getProfilePicURL() }}"/>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user