diff --git a/requirements.txt b/requirements.txt index 0627233..27e0841 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,7 +14,6 @@ psycopg2==2.9.6 djangorestframework django-htmx==1.14.0 wagtail-metadata==4.0.3 -humanize==4.6.0 django-plausible==0.5.0 sentry-sdk==1.25.0 django-sri==0.6.0 diff --git a/website/common/models.py b/website/common/models.py index 314796f..afc684d 100644 --- a/website/common/models.py +++ b/website/common/models.py @@ -1,6 +1,7 @@ from datetime import timedelta from typing import Any, Optional, Type +from django.contrib.humanize.templatetags.humanize import NaturalTimeFormatter from django.contrib.syndication.views import Feed from django.core.paginator import EmptyPage from django.core.paginator import Page as PaginatorPage @@ -8,6 +9,7 @@ from django.core.paginator import Paginator from django.db import models from django.http.request import HttpRequest from django.http.response import Http404, HttpResponse, HttpResponseBadRequest +from django.utils import timezone from django.utils.decorators import method_decorator from django.utils.functional import cached_property, classproperty from django.utils.text import slugify @@ -113,6 +115,12 @@ class BaseContentPage(BasePage, MetadataMixin): """ return timedelta(seconds=(self.word_count / 265) * 60) + @cached_property + def reading_time_display(self) -> str: + return NaturalTimeFormatter.string_for( + timezone.now() - self.reading_time + ).removesuffix(" ago") + @cached_property def show_reading_time(self) -> bool: """ diff --git a/website/common/templates/common/content-details.html b/website/common/templates/common/content-details.html index 006af58..109c179 100644 --- a/website/common/templates/common/content-details.html +++ b/website/common/templates/common/content-details.html @@ -1,4 +1,4 @@ -{% load wagtailcore_tags humanize_tags cache util_tags %} +{% load wagtailcore_tags cache util_tags %} {% cache FRAGMENT_CACHE_TTL|jitter:FRAGMENT_CACHE_TTL_JITTER "content-details" page.id request.is_preview %}
@@ -16,7 +16,7 @@ - {{ page.reading_time|naturaldelta }} + {{ page.reading_time_display }}
{% endif %} diff --git a/website/common/templates/wagtailmetadata/parts/tags.html b/website/common/templates/wagtailmetadata/parts/tags.html index 1ffcff1..4467e08 100644 --- a/website/common/templates/wagtailmetadata/parts/tags.html +++ b/website/common/templates/wagtailmetadata/parts/tags.html @@ -1,12 +1,10 @@ {% extends "wagtailmetadata/parts/tags.html" %} -{% load humanize_tags %} - {% block twitter %} {{ block.super }} {% if object.show_reading_time %} - + {% endif %} {% endblock %} diff --git a/website/utils/templatetags/humanize_tags.py b/website/utils/templatetags/humanize_tags.py deleted file mode 100644 index 11b6898..0000000 --- a/website/utils/templatetags/humanize_tags.py +++ /dev/null @@ -1,6 +0,0 @@ -import humanize -from django.template import Library - -register = Library() - -register.filter(humanize.naturaldelta)