Ensure dates are always rendered without the leading 0
authorAlex Chan <alex@alexwlchan.net>
Fri, 7 Feb 2020 19:28:33 +0000 (19:28 +0000)
committerAlex Chan <alex@alexwlchan.net>
Fri, 7 Feb 2020 19:28:33 +0000 (19:28 +0000)
If there was a datetime.date() object in the YAML front matter (that is,
a date_read without string quotes), it would be formatted with a leading
zero, e.g. "07 February 2020".  Dates that were strings would be shown
w/o,  e.g. "7 February 2020".

Now all dates are stored consistently, regardless of how they're stored.

scripts/render_html.py

index b427ef4..b68ae98 100755 (executable)
@@ -141,7 +141,7 @@ def render_markdown(text):
 
 def render_date(date_value):
     if isinstance(date_value, datetime.date):
-        return date_value.strftime("%d %B %Y")
+        return date_value.strftime("%-d %B %Y")
 
     date_match = re.match(
         r"^(?P<year>\d{4})-(?P<month>\d{2})(?:-(?P<day>\d{2}))?$", date_value
@@ -155,7 +155,7 @@ def render_date(date_value):
     )
 
     if date_match.group("day"):
-        return date_obj.strftime("%-d %B %Y")
+        return render_date(date_obj)
     else:
         return date_obj.strftime("%B %Y")