From 4bc6e7d3541034f70bd24a226e7a436ece9b3272 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Fri, 11 Jul 2025 11:19:02 +0200 Subject: [PATCH] add time to datePublished --- hub/services/templatetags/json_ld_tags.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/hub/services/templatetags/json_ld_tags.py b/hub/services/templatetags/json_ld_tags.py index 3741bfe..6efa78c 100644 --- a/hub/services/templatetags/json_ld_tags.py +++ b/hub/services/templatetags/json_ld_tags.py @@ -1,7 +1,9 @@ -# hub/services/templatetags/json_ld_tags.py +from datetime import datetime, time from django import template from django.urls import resolve, Resolver404 from django.utils.safestring import mark_safe +from django.utils import timezone as django_timezone + import json register = template.Library() @@ -332,8 +334,10 @@ def json_ld_structured_data(context): } # Add publication date using article_date field - if article.article_date: - data["datePublished"] = article.article_date.isoformat() + article_datetime = django_timezone.make_aware( + datetime.combine(article.article_date, time.min) + ) + data["datePublished"] = article_datetime.isoformat() # Add modification date if article.updated_at: