aboutsummaryrefslogtreecommitdiff
path: root/webmentions_ssg
diff options
context:
space:
mode:
Diffstat (limited to 'webmentions_ssg')
-rw-r--r--webmentions_ssg/__init__.py4
-rw-r--r--webmentions_ssg/template_filters.py31
-rw-r--r--webmentions_ssg/templates/dashboard.html6
-rw-r--r--webmentions_ssg/templates/received.html17
-rw-r--r--webmentions_ssg/templates/received_detail.html15
-rw-r--r--webmentions_ssg/templates/sent.html10
-rw-r--r--webmentions_ssg/templates/sent_source.html30
-rw-r--r--webmentions_ssg/templates/status.html10
8 files changed, 89 insertions, 34 deletions
diff --git a/webmentions_ssg/__init__.py b/webmentions_ssg/__init__.py
index 174250e..b4b9f72 100644
--- a/webmentions_ssg/__init__.py
+++ b/webmentions_ssg/__init__.py
@@ -23,6 +23,7 @@ from .config import (
)
from .extensions import bootstrap, csrf, db, huey, limiter, mail, migrate
from .net import is_http_url
+from .template_filters import relative_time, utc_isoformat, utc_timestamp
from .version import APP_NAME as APP_NAME
from .version import VERSION
from .views import webmentions_bp
@@ -140,6 +141,9 @@ def create_app(config_class: type[DefaultConfig] | None = None) -> Flask:
return {"VERSION": VERSION}
app.add_template_filter(is_http_url)
+ app.add_template_filter(relative_time)
+ app.add_template_filter(utc_isoformat)
+ app.add_template_filter(utc_timestamp)
app.register_blueprint(webmentions_bp)
diff --git a/webmentions_ssg/template_filters.py b/webmentions_ssg/template_filters.py
new file mode 100644
index 0000000..e6cac2d
--- /dev/null
+++ b/webmentions_ssg/template_filters.py
@@ -0,0 +1,31 @@
+# SPDX-FileCopyrightText: 2026 Dennis Fink <me+coding@dennisfink.me>
+#
+# SPDX-License-Identifier: BSD-3-Clause
+
+"""Helpers for displaying UTC timestamps in templates."""
+
+from datetime import UTC, datetime
+
+import humanize
+
+
+def as_utc(value: datetime) -> datetime:
+ """Normalize a timestamp to UTC, treating timezone-naive DB values as UTC."""
+ if value.tzinfo is None:
+ return value.replace(tzinfo=UTC)
+ return value.astimezone(UTC)
+
+
+def utc_isoformat(value: datetime) -> str:
+ """Return an unambiguous machine-readable timestamp for the time element."""
+ return as_utc(value).isoformat()
+
+
+def utc_timestamp(value: datetime) -> str:
+ """Return the complete UTC timestamp for the hover tooltip."""
+ return as_utc(value).strftime("%Y-%m-%d %H:%M:%S UTC")
+
+
+def relative_time(value: datetime) -> str:
+ """Render a timestamp as a human-readable age relative to the current UTC time."""
+ return humanize.naturaltime(datetime.now(UTC) - as_utc(value))
diff --git a/webmentions_ssg/templates/dashboard.html b/webmentions_ssg/templates/dashboard.html
index 70e2bf0..b020d46 100644
--- a/webmentions_ssg/templates/dashboard.html
+++ b/webmentions_ssg/templates/dashboard.html
@@ -118,8 +118,10 @@ SPDX-License-Identifier: BSD-3-Clause
<div class="card-body">
<h3 class="h6 text-body-secondary">Last completed source scan</h3>
{% if last_scan %}
- <time datetime="{{ last_scan.isoformat() }}" class="fs-5">
- {{ last_scan.strftime("%Y-%m-%d %H:%M:%S") }} UTC
+ <time datetime="{{ last_scan | utc_isoformat }}"
+ class="fs-5"
+ title="{{ last_scan | utc_timestamp }}">
+ {{ last_scan | relative_time }}
</time>
{% else %}
<p class="text-body-secondary mb-0">No completed scan yet</p>
diff --git a/webmentions_ssg/templates/received.html b/webmentions_ssg/templates/received.html
index 2edf881..8931601 100644
--- a/webmentions_ssg/templates/received.html
+++ b/webmentions_ssg/templates/received.html
@@ -194,8 +194,9 @@ SPDX-License-Identifier: BSD-3-Clause
<a href="{{ webmention.source }}">{{ webmention.source }}</a>
<div class="small mt-1 d-md-none">
Received
- <time datetime="{{ webmention.created_at.isoformat() }}">
- {{ webmention.created_at.strftime("%Y-%m-%d %H:%M:%S") }}
+ <time datetime="{{ webmention.created_at | utc_isoformat }}"
+ title="{{ webmention.created_at | utc_timestamp }}">
+ {{ webmention.created_at | relative_time }}
</time>
</div>
</td>
@@ -203,15 +204,15 @@ SPDX-License-Identifier: BSD-3-Clause
<a href="{{ webmention.target }}">{{ webmention.target }}</a>
</td>
<td class="text-nowrap d-none d-md-table-cell">
- <time datetime="{{ webmention.created_at.isoformat() }}"
- title="{{ webmention.created_at.strftime('%Y-%m-%d %H:%M:%S') }} UTC">
- {{ webmention.created_at.strftime("%Y-%m-%d %H:%M:%S") }}
+ <time datetime="{{ webmention.created_at | utc_isoformat }}"
+ title="{{ webmention.created_at | utc_timestamp }}">
+ {{ webmention.created_at | relative_time }}
</time>
</td>
<td class="text-nowrap d-none d-md-table-cell">
- <time datetime="{{ webmention.updated_at.isoformat() }}"
- title="{{ webmention.updated_at.strftime('%Y-%m-%d %H:%M:%S') }} UTC">
- {{ webmention.updated_at.strftime("%Y-%m-%d %H:%M:%S") }}
+ <time datetime="{{ webmention.updated_at | utc_isoformat }}"
+ title="{{ webmention.updated_at | utc_timestamp }}">
+ {{ webmention.updated_at | relative_time }}
</time>
</td>
<td>
diff --git a/webmentions_ssg/templates/received_detail.html b/webmentions_ssg/templates/received_detail.html
index 32d3e05..38830bf 100644
--- a/webmentions_ssg/templates/received_detail.html
+++ b/webmentions_ssg/templates/received_detail.html
@@ -58,11 +58,17 @@ SPDX-License-Identifier: BSD-3-Clause
</dd>
<dt class="col-md-3">Received</dt>
<dd class="col-md-9">
- <time datetime="{{ webmention.created_at.isoformat() }}">{{ webmention.created_at.strftime("%Y-%m-%d %H:%M:%S") }} UTC</time>
+ <time datetime="{{ webmention.created_at | utc_isoformat }}"
+ title="{{ webmention.created_at | utc_timestamp }}">
+ {{ webmention.created_at | relative_time }}
+ </time>
</dd>
<dt class="col-md-3">Last updated</dt>
<dd class="col-md-9">
- <time datetime="{{ webmention.updated_at.isoformat() }}">{{ webmention.updated_at.strftime("%Y-%m-%d %H:%M:%S") }} UTC</time>
+ <time datetime="{{ webmention.updated_at | utc_isoformat }}"
+ title="{{ webmention.updated_at | utc_timestamp }}">
+ {{ webmention.updated_at | relative_time }}
+ </time>
</dd>
<dt class="col-md-3">Recovery attempts</dt>
<dd class="col-md-9">
@@ -128,8 +134,9 @@ SPDX-License-Identifier: BSD-3-Clause
<span class="badge {{ event_style.badge }}">{{ event_style.label }}</span>
<strong>{{ event.action }}</strong>
<time class="ms-auto text-body-secondary small"
- datetime="{{ event.occurred_at.isoformat() }}">
- {{ event.occurred_at.strftime("%Y-%m-%d %H:%M:%S") }} UTC
+ datetime="{{ event.occurred_at | utc_isoformat }}"
+ title="{{ event.occurred_at | utc_timestamp }}">
+ {{ event.occurred_at | relative_time }}
</time>
</div>
<div class="small text-body-secondary">Recovery attempts: {{ event.recovery_attempts }}</div>
diff --git a/webmentions_ssg/templates/sent.html b/webmentions_ssg/templates/sent.html
index d949f01..d2a319d 100644
--- a/webmentions_ssg/templates/sent.html
+++ b/webmentions_ssg/templates/sent.html
@@ -58,13 +58,15 @@ SPDX-License-Identifier: BSD-3-Clause
<td>{{ source.sent_webmentions | length }}</td>
<td class="d-none d-md-table-cell">{{ source.revision }}</td>
<td class="text-nowrap d-none d-md-table-cell">
- <time datetime="{{ source.created_at.isoformat() }}">
- {{ source.created_at.strftime("%Y-%m-%d %H:%M:%S") }}
+ <time datetime="{{ source.created_at | utc_isoformat }}"
+ title="{{ source.created_at | utc_timestamp }}">
+ {{ source.created_at | relative_time }}
</time>
</td>
<td class="text-nowrap d-none d-md-table-cell">
- <time datetime="{{ source.last_seen_at.isoformat() }}">
- {{ source.last_seen_at.strftime("%Y-%m-%d %H:%M:%S") }}
+ <time datetime="{{ source.last_seen_at | utc_isoformat }}"
+ title="{{ source.last_seen_at | utc_timestamp }}">
+ {{ source.last_seen_at | relative_time }}
</time>
</td>
<td>
diff --git a/webmentions_ssg/templates/sent_source.html b/webmentions_ssg/templates/sent_source.html
index 6e34458..33e26a2 100644
--- a/webmentions_ssg/templates/sent_source.html
+++ b/webmentions_ssg/templates/sent_source.html
@@ -51,20 +51,23 @@ SPDX-License-Identifier: BSD-3-Clause
</dd>
<dt class="col-sm-2">Created at</dt>
<dd class="col-sm-4">
- <time datetime="{{ source.created_at.isoformat() }}">
- {{ source.created_at.strftime("%Y-%m-%d %H:%M:%S") }}
+ <time datetime="{{ source.created_at | utc_isoformat }}"
+ title="{{ source.created_at | utc_timestamp }}">
+ {{ source.created_at | relative_time }}
</time>
</dd>
<dt class="col-sm-2">Last seen at</dt>
<dd class="col-sm-4">
- <time datetime="{{ source.last_seen_at.isoformat() }}">
- {{ source.last_seen_at.strftime("%Y-%m-%d %H:%M:%S") }}
+ <time datetime="{{ source.last_seen_at | utc_isoformat }}"
+ title="{{ source.last_seen_at | utc_timestamp }}">
+ {{ source.last_seen_at | relative_time }}
</time>
</dd>
<dt class="col-sm-2">Revised at</dt>
<dd class="col-sm-4">
- <time datetime="{{ source.revised_at.isoformat() }}">
- {{ source.revised_at.strftime("%Y-%m-%d %H:%M:%S") }}
+ <time datetime="{{ source.revised_at | utc_isoformat }}"
+ title="{{ source.revised_at | utc_timestamp }}">
+ {{ source.revised_at | relative_time }}
</time>
</dd>
<dt class="col-sm-2">Deleted at</dt>
@@ -72,8 +75,9 @@ SPDX-License-Identifier: BSD-3-Clause
{% if source.deleted_at is none %}
N/A
{% else %}
- <time datetime="{{ source.deleted_at.isoformat() }}">
- {{ source.deleted_at.strftime("%Y-%m-%d %H:%M:%S") }}
+ <time datetime="{{ source.deleted_at | utc_isoformat }}"
+ title="{{ source.deleted_at | utc_timestamp }}">
+ {{ source.deleted_at | relative_time }}
</time>
{% endif %}
</dd>
@@ -169,8 +173,9 @@ SPDX-License-Identifier: BSD-3-Clause
<strong>Attempted:</strong>
<br>
{% if webmention.last_attempted_at is not none %}
- <time datetime="{{ webmention.last_attempted_at.isoformat() }}">
- {{ webmention.last_attempted_at.strftime("%Y-%m-%d %H:%M:%S") }}
+ <time datetime="{{ webmention.last_attempted_at | utc_isoformat }}"
+ title="{{ webmention.last_attempted_at | utc_timestamp }}">
+ {{ webmention.last_attempted_at | relative_time }}
</time>
{% else %}
—
@@ -180,8 +185,9 @@ SPDX-License-Identifier: BSD-3-Clause
<strong>Sent:</strong>
<br>
{% if webmention.last_sent_at is not none %}
- <time datetime="{{ webmention.last_sent_at.isoformat() }}">
- {{ webmention.last_sent_at.strftime("%Y-%m-%d %H:%M:%S") }}
+ <time datetime="{{ webmention.last_sent_at | utc_isoformat }}"
+ title="{{ webmention.last_sent_at | utc_timestamp }}">
+ {{ webmention.last_sent_at | relative_time }}
</time>
{% else %}
—
diff --git a/webmentions_ssg/templates/status.html b/webmentions_ssg/templates/status.html
index a9a39b4..27821ff 100644
--- a/webmentions_ssg/templates/status.html
+++ b/webmentions_ssg/templates/status.html
@@ -44,14 +44,16 @@ SPDX-License-Identifier: BSD-3-Clause
</dd>
<dt class="col-sm-3">Received</dt>
<dd class="col-sm-9">
- <time datetime="{{ webmention.created_at.isoformat() }}">
- {{ webmention.created_at.strftime("%Y-%m-%d %H:%M:%S %Z") }}
+ <time datetime="{{ webmention.created_at | utc_isoformat }}"
+ title="{{ webmention.created_at | utc_timestamp }}">
+ {{ webmention.created_at | relative_time }}
</time>
</dd>
<dt class="col-sm-3">Last updated</dt>
<dd class="col-sm-9">
- <time datetime="{{ webmention.updated_at.isoformat() }}">
- {{ webmention.updated_at.strftime("%Y-%m-%d %H:%M:%S %Z") }}
+ <time datetime="{{ webmention.updated_at | utc_isoformat }}"
+ title="{{ webmention.updated_at | utc_timestamp }}">
+ {{ webmention.updated_at | relative_time }}
</time>
</dd>
<dt class="col-sm-3">ID</dt>