remove moment.js to decrease carbon usage

This commit is contained in:
rimu 2024-08-23 11:14:47 +12:00
parent 5a02eb9ba0
commit 9bad635805
26 changed files with 30 additions and 41 deletions

View file

@ -10,7 +10,6 @@ from flask_migrate import Migrate
from flask_login import LoginManager
from flask_bootstrap import Bootstrap5
from flask_mail import Mail
from flask_moment import Moment
from flask_babel import Babel, lazy_gettext as _l
from flask_caching import Cache
from celery import Celery
@ -39,7 +38,6 @@ login.login_view = 'auth.login'
login.login_message = _l('Please log in to access this page.')
mail = Mail()
bootstrap = Bootstrap5()
moment = Moment()
babel = Babel(locale_selector=get_locale)
cache = Cache()
celery = Celery(__name__, broker=Config.CELERY_BROKER_URL)
@ -61,7 +59,6 @@ def create_app(config_class=Config):
login.init_app(app)
mail.init_app(app)
bootstrap.init_app(app)
moment.init_app(app)
make_searchable(db.metadata)
babel.init_app(app, locale_selector=get_locale)
cache.init_app(app)

View file

@ -3,7 +3,6 @@ from datetime import timedelta
from random import randint
import flask
from flask_caching import CachedResponse
from sqlalchemy.sql.operators import or_, and_
from app import db, cache
@ -15,7 +14,6 @@ from app.email import send_email
from app.inoculation import inoculation
from app.main import bp
from flask import g, session, flash, request, current_app, url_for, redirect, make_response, jsonify
from flask_moment import moment
from flask_login import current_user, login_required
from flask_babel import _, get_locale
from sqlalchemy import desc, text

View file

@ -14,8 +14,6 @@ curl -o js/markdown/downarea.js -L https://codeberg.org/PieFed/downarea2/raw/bra
# https://htmx.org/ (Zero-Clause BSD)
curl -o js/htmx.min.js -L https://unpkg.com/htmx.org@2.0.0
# https://momentjs.com/ (MIT license)
curl -o js/moment-with-locales.min.js -L https://momentjs.com/downloads/moment-with-locales.min.js
# ToDo: coolfieldset.js

View file

@ -32,7 +32,7 @@
</tr>
{% for activity in activities.items %}
<tr>
<td>{{ moment(activity.created_at).fromNow() }}</td>
<td>{{ arrow.get(activity.created_at).humanize(locale=locale) }}</td>
<td>{{ activity.direction }}</td>
<td>{{ activity.activity_id }}</td>
<td>{{ activity.activity_type if activity.activity_type else '' }}</td>

View file

@ -33,7 +33,7 @@
<td><a href="mailto:{{ registration.user.email }}">{{ registration.user.email }}</a></td>
<td>{{ '<span class="green">&check;</span>'|safe if registration.user.verified else '<span class="red">&cross;</span>'|safe }}</td>
<td>{{ registration.answer }}</td>
<td>{{ moment(registration.created_at).fromNow() }}</td>
<td>{{ arrow.get(registration.created_at).humanize(locale=locale) }}</td>
<td>{{ registration.user.ip_address if registration.user.ip_address }}<br />{{ registration.user.ip_address_country if registration.user.ip_address_country }}</td>
<td>{{ registration.user.referrer if registration.user.referrer }} </td>
<td><a href="{{ url_for('admin.admin_approve_registrations_approve', user_id=registration.user.id) }}" class="btn btn-sm btn-primary">{{ _('Approve') }}</a>
@ -71,7 +71,7 @@
<td><a href="mailto:{{ registration.user.email }}">{{ registration.user.email }}</a></td>
<td>{{ '<span class="green">&check;</span>'|safe if registration.user.verified else '<span class="red">&cross;</span>'|safe }}</td>
<td>{{ registration.answer }}</td>
<td>{{ moment(registration.created_at).fromNow() }}</td>
<td>{{ arrow.get(registration.created_at).humanize(locale=locale) }}</td>
<td>{{ registration.user.ip_address if registration.user.ip_address }}<br />{{ registration.user.ip_address_country if registration.user.ip_address_country }}</td>
<td>{{ registration.user.referrer if registration.user.referrer }} </td>
<td>

View file

@ -13,8 +13,8 @@
<form method="post" enctype="multipart/form-data" id="add_local_user_form">
{{ form.csrf_token() }}
{{ user.about_html|safe if user.about_html }}
<p>Created: {{ moment(user.created).format('MMMM Do YYYY, h:mm:ss a') }}</p>
<p>Last active: {{ moment(user.last_seen).format('MMMM Do YYYY, h:mm:ss a') }}</p>
<p>Created: {{ arrow.get(user.created).humanize(locale=locale) }}</p>
<p>Last active: {{ arrow.get(user.last_seen).humanize(locale=locale) }}</p>
<p>Email: <a href="mailto:{{ user.email }}">{{ user.email }}</a></p>
<p>Matrix: {{ user.matrix_user_id if user.matrix_user_id }}</p>
{% if user.avatar_id %}

View file

@ -31,7 +31,7 @@
<td>{{ report.reasons }}</td>
<td>{{ report.description }}</td>
<td>{{ report.type_text() }}</td>
<td>{{ moment(report.created_at).fromNow() }}</td>
<td>{{ arrow.get(report.created_at).humanize(locale=locale) }}</td>
<td>
{% if report.suspect_conversation_id %}
<a href="/chat/{{ report.suspect_conversation_id }}#message">View</a>

View file

@ -37,7 +37,7 @@
{{ user.display_name() }}</a></td>
<td>{% if user.is_local() %}Local{% else %}<a href="{{ user.ap_profile_id }}">Remote</a>{% endif %}</td>
<td>{% if request.args.get('local_remote', '') == 'local' %}
{{ moment(user.last_seen).fromNow() }}
{{ arrow.get(user.last_seen).humanize(locale=locale) }}
{% else %}
{{ user.last_seen }}
{% endif %}

View file

@ -39,7 +39,7 @@
{{ user.display_name() }}</a></td>
<td>{% if user.is_local() %}Local{% else %}<a href="{{ user.ap_profile_id }}">Remote</a>{% endif %}</td>
<td>{% if request.args.get('local_remote', '') == 'local' %}
{{ moment(user.last_seen).fromNow() }}
{{ arrow.get(user.last_seen).humanize(locale=locale) }}
{% else %}
{{ user.last_seen }}
{% endif %}

View file

@ -272,10 +272,6 @@
{% endblock -%}
{% block scripts -%}
{% if not low_bandwidth -%}
{{ str(moment.include_moment(local_js='/static/js/moment-with-locales.min.js')).replace('<script>', '<script nonce="' + session['nonce'] + '">')|safe }}
{{ str(moment.lang(g.locale)).replace('<script>', '<script nonce="' + session['nonce'] + '">')|safe }}
{% endif -%}
{% endblock -%}
{% if not low_bandwidth -%}
{{ str(bootstrap.load_js()).replace('<script ', '<script nonce="' + session['nonce'] + '" ')|safe }}

View file

@ -66,7 +66,7 @@
{% for message in messages %}
<div id="message_{{ message.id }}" class="card message {{ 'from_other_party' if message.sender_id != current_user.id else 'from_me' }}">
<div class="message_body">
<span class="message_created_at text-muted small">{{ moment(message.created_at).fromNow(refresh=True) }}</span>
<span class="message_created_at text-muted small">{{ arrow.get(message.created_at).humanize(locale=locale) }}</span>
<span class="message_sender"><a href="/u/{{ message.sender.link() }}">{{ message.sender.display_name() }}</a></span>: {{ message.body_html|safe }}
</div>
</div>

View file

@ -47,7 +47,7 @@
<td>{{ report.reasons }}</td>
<td>{{ report.description }}</td>
<td>{{ report.type_text() }}</td>
<td>{{ moment(report.created_at).fromNow() }}</td>
<td>{{ arrow.get(report.created_at).humanize(locale=locale) }}</td>
<td>
<div class="dropdown">
<button class="btn btn-primary btn-sm dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">

View file

@ -42,7 +42,7 @@
<a href="/u/{{ user.link() }}">{{ render_username(user) }}</a>
</td>
<td>{% if user.is_local() %} Local {% else %} <a href="{{ user.ap_profile_id }}">{{ user.ap_domain }}</a>{% endif %}</td>
<td>{{ moment(user.last_seen).fromNow() }} </td>
<td>{{ arrow.get(user.last_seen).humanize(locale=locale) }} </td>
<td>{{ user.ip_address if user.ip_address }} </td>
<td>
<div class="dropdown">

View file

@ -35,7 +35,7 @@
<tbody>
{% for modlog_entry in modlog_entries.items %}
<tr>
<td>{{ moment(modlog_entry.created_at).fromNow() }}</td>
<td>{{ arrow.get(modlog_entry.created_at).humanize(locale=locale) }}</td>
<td>{{ render_username(modlog_entry.author) }}</td>
<td>{{ modlog_entry.action_to_str() }}
{% if modlog_entry.link and modlog_entry.link_text -%}

View file

@ -35,7 +35,7 @@
{% for revision in revisions %}
<tr>
<td>{{ render_username(revision.author) }}</td>
<td>{{ moment(revision.edited_at).fromNow() }}</td>
<td>{{ arrow.get(revision.edited_at).humanize(locale=locale) }}</td>
<td class="text-right">{% if page.can_edit(current_user, community) %}
<div class="dropdown">
<button class="btn btn-primary btn-sm dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">

View file

@ -110,7 +110,7 @@
<th scope="row" class="pl-0"><a href="/c/{{ community.link() }}" aria-label="{{ _('Browse %(name)s', name=community.display_name()) }}">{{ community.display_name() }}</a></th>
<td>{{ community.post_count }}</td>
<td>{{ community.post_reply_count }}</td>
<td>{{ moment(community.last_active).fromNow(refresh=True) }}</td>
<td>{{ arrow.get(community.last_active).humanize(locale=locale) }}</td>
</tr>
{% endfor -%}
</tbody>

View file

@ -21,7 +21,7 @@
<tbody>
{% for modlog_entry in modlog_entries.items %}
<tr>
<td>{{ moment(modlog_entry.created_at).fromNow() }}</td>
<td>{{ arrow.get(modlog_entry.created_at).humanize(locale=locale) }}</td>
{% if can_see_names %}<td>{{ render_username(modlog_entry.author) }}</td>{% endif %}
<td>{{ modlog_entry.action_to_str() }}
{% if modlog_entry.link and modlog_entry.link_text -%}

View file

@ -26,8 +26,8 @@
{% endif -%}
<p>{% if post.reports > 0 and current_user.is_authenticated and post.community.is_moderator(current_user) -%}
<span class="red fe fe-report" title="{{ _('Reported. Check post for issues.') }}"></span>
{% endif -%}<small>submitted {{ moment(post.posted_at).fromNow() }} by {{ render_username(post.author) }}
{% if post.edited_at -%} edited {{ moment(post.edited_at).fromNow() }}{% endif -%}
{% endif -%}<small>submitted {{ arrow.get(post.posted_at).humanize(locale=locale) }} by {{ render_username(post.author) }}
{% if post.edited_at -%} edited {{ arrow.get(post.edited_at).humanize(locale=locale) }}{% endif -%}
</small></p>
<div class="post_image">
{% if post.image_id -%}
@ -80,9 +80,9 @@
{% endif -%}
<p>{% if post.reports > 0 and current_user.is_authenticated and post.community.is_moderator(current_user) -%}
<span class="red fe fe-report" title="{{ _('Reported. Check post for issues.') }}"></span>
{% endif -%}<small>submitted {{ moment(post.posted_at).fromNow() }} by
{% endif -%}<small>submitted {{ arrow.get(post.posted_at).humanize(locale=locale) }} by
{{ render_username(post.author) }}
{% if post.edited_at -%} edited {{ moment(post.edited_at).fromNow() }}{% endif -%}</small>
{% if post.edited_at -%} edited {{ arrow.get(post.edited_at).humanize(locale=locale) }}{% endif -%}</small>
</p>
{% if post.type == POST_TYPE_LINK -%}
<p><a href="{{ post.url }}" rel="nofollow ugc" target="_blank" class="post_link" aria-label="Go to post url">{{ post.url|shorten_url }}
@ -164,7 +164,7 @@
{% endfor -%}
</ul>
<p>{{ _('Total votes: %(total_votes)d.', total_votes=poll_total_votes) }}</p>
<p>{{ _('Poll closes') }} {{ moment(poll_data.end_poll).fromNow(refresh=True) }}.</p>
<p>{{ _('Poll closes') }} {{ arrow.get(poll_data.end_poll).humanize(locale=locale) }}.</p>
{% elif poll_form -%}
{% if current_user.is_authenticated -%}
<form action='/poll/{{ post.id }}/vote' method="post">

View file

@ -28,8 +28,8 @@
{% endif -%}
</div>
<div class="col-auto text-muted small">
{{ moment(post_reply.posted_at).fromNow(refresh=True) }}
{% if post_reply.edited_at -%}, edited {{ moment(post_reply.edited_at).fromNow(refresh=True) }} {% endif -%}
{{ arrow.get(post_reply.posted_at).humanize(locale=locale) }}
{% if post_reply.edited_at -%}, edited {{ arrow.get(post_reply.edited_at).humanize(locale=locale) }} {% endif -%}
</div>
<div class="col-auto">
{% if post_reply.reports and current_user.is_authenticated and post_reply.post.community.is_moderator(current_user) -%}

View file

@ -74,7 +74,7 @@
</h3>
<span class="author small">{% if show_post_community -%}<a href="/c/{{ post.community.link() }}" aria-label="{{ _('Go to community %(name)s', name=post.community.name) }}">c/{{ post.community.name }}</a>{% endif -%}
by {{ render_username(post.author) }} {{ moment(post.last_active if sort == 'active' else post.posted_at).fromNow() }}</span>
by {{ render_username(post.author) }} {{ arrow.get(post.last_active if sort == 'active' else post.posted_at).humanize(locale=locale) }}</span>
<div class="post_utilities">
<a href="{{ url_for('activitypub.post_ap', post_id=post.id, sort='new' if sort == 'active' else None, _anchor='post_replies') }}" aria-label="{{ _('View comments') }}"><span class="fe fe-reply"></span> <span aria-label="{{ _('Number of comments:') }}">{{ post.reply_count }}</span></a>
{% if post.type == POST_TYPE_IMAGE -%}

View file

@ -20,7 +20,7 @@
{{ render_username(comment['comment'].author) }}
{% endwith -%}
{% if comment['comment'].author.id == post.author.id %}<span title="Submitter of original post" aria-label="submitter" class="small">[OP] </span>{% endif %}
<span class="text-muted small">{{ moment(comment['comment'].posted_at).fromNow(refresh=True) }}{% if comment['comment'].edited_at %}, edited {{ moment(comment['comment'].edited_at).fromNow(refresh=True) }} {% endif %}</span>
<span class="text-muted small">{{ arrow.get(comment['comment'].posted_at).humanize(locale=locale) }}{% if comment['comment'].edited_at %}, edited {{ arrow.get(comment['comment'].edited_at).humanize(locale=locale) }} {% endif %}</span>
<a class="unhide" href="#"><span class="fe fe-expand"></span></a>
{% if comment['comment'].reports and current_user.is_authenticated and post.community.is_moderator(current_user)%}
<span class="red fe fe-report" title="{{ _('Reported. Check comment for issues.') }}"></span>

View file

@ -82,7 +82,7 @@
{{ render_username(comment['comment'].author) }}
{% endwith -%}
{% if comment['comment'].author.id == post.author.id -%}<span title="Submitter of original post" aria-label="{{ _('Post creator') }}" class="small">[OP] </span>{% endif -%}
<span class="text-muted small" aria_label="{{ _('When: ') }}">{{ moment(comment['comment'].posted_at).fromNow(refresh=True) }}{% if comment['comment'].edited_at -%}, edited {{ moment(comment['comment'].edited_at).fromNow(refresh=True) }} {% endif -%}</span>
<span class="text-muted small" aria_label="{{ _('When: ') }}">{{ arrow.get(comment['comment'].posted_at).humanize(locale=locale) }}{% if comment['comment'].edited_at -%}, edited {{ arrow.get(comment['comment'].edited_at).humanize(locale=locale) }} {% endif -%}</span>
<a class="unhide" href="#"><span class="fe fe-expand"></span></a>
{% if comment['comment'].reports and current_user.is_authenticated and post.community.is_moderator(current_user)%}
<span class="red fe fe-report" title="{{ _('Reported. Check comment for issues.') }}"></span>

View file

@ -30,7 +30,7 @@
<a href="{{ url_for('user.notification_goto', notification_id=notification.id) }}">{{ notification.title }}</a>
{% if not notification.read %}</strong>{% endif %}
</td>
<td>{{ moment(notification.created_at).fromNow(refresh=True) }}</td>
<td>{{ arrow.get(notification.created_at).humanize(locale=locale) }}</td>
<td>
<a href="{{ url_for('user.notification_delete', notification_id=notification.id) }}" class="no-underline"><span class="fe fe-delete"></span> {{ _('Delete') }}</a>
</td>

View file

@ -89,8 +89,8 @@
{% endif %}
</div>
<p class="small">{{ _('Joined') }}: {{ moment(user.created).fromNow(refresh=True) }}<br />
{% if current_user.is_authenticated and current_user.is_admin() and user.last_seen %}{{ _('Active') }}: {{ moment(user.last_seen).fromNow(refresh=True) }}<br />{% endif %}
<p class="small">{{ _('Joined') }}: {{ arrow.get(user.created).humanize(locale=locale) }}<br />
{% if current_user.is_authenticated and current_user.is_admin() and user.last_seen %}{{ _('Active') }}: {{ arrow.get(user.last_seen).humanize(locale=locale) }}<br />{% endif %}
{% if user.bot %}
{{ _('Bot Account') }}<br />
{% endif %}

View file

@ -6,7 +6,7 @@ from flask_babel import get_locale
from flask_login import current_user
from app import create_app, db, cli
import os, click
import os, arrow
from flask import session, g, json, request, current_app
from app.constants import POST_TYPE_LINK, POST_TYPE_IMAGE, POST_TYPE_ARTICLE, POST_TYPE_VIDEO, POST_TYPE_POLL, \
SUBSCRIPTION_MODERATOR, SUBSCRIPTION_MEMBER, SUBSCRIPTION_OWNER, SUBSCRIPTION_PENDING
@ -24,6 +24,7 @@ def app_context_processor():
def getmtime(filename):
return os.path.getmtime('app/static/' + filename)
return dict(getmtime=getmtime, instance_domain=current_app.config['SERVER_NAME'], debug_mode=current_app.debug,
arrow=arrow, locale=g.locale,
POST_TYPE_LINK=POST_TYPE_LINK, POST_TYPE_IMAGE=POST_TYPE_IMAGE,
POST_TYPE_ARTICLE=POST_TYPE_ARTICLE, POST_TYPE_VIDEO=POST_TYPE_VIDEO, POST_TYPE_POLL=POST_TYPE_POLL,
SUBSCRIPTION_MODERATOR=SUBSCRIPTION_MODERATOR, SUBSCRIPTION_MEMBER=SUBSCRIPTION_MEMBER,

View file

@ -7,7 +7,6 @@ flask-migrate==4.0.4
flask-login==0.6.2
email-validator==2.0.0
flask-mail==0.9.1
flask-moment==1.0.5
flask-babel==3.1.0
psycopg2-binary
requests==2.31.0