feat: formatted date times one website

This commit is contained in:
Leyla Becker 2026-02-19 16:32:11 -06:00
parent dffd14a19f
commit 927f13b623
5 changed files with 51 additions and 17 deletions

View file

@ -136,6 +136,28 @@
</script>
{% endif %}
<script>
document.querySelectorAll('.localizable-time').forEach(function(el) {
var iso = el.getAttribute('datetime');
if (!iso) return;
try {
var date = new Date(iso);
if (isNaN(date.getTime())) return;
var options = {
year: 'numeric',
month: 'long',
day: 'numeric',
hour: 'numeric',
minute: '2-digit',
timeZoneName: 'short'
};
el.textContent = date.toLocaleString(undefined, options);
} catch (e) {
// Keep server-rendered fallback on error
}
});
</script>
<footer>
<div>
<!-- Social Things -->

View file

@ -10,9 +10,9 @@ layout: base.njk
{% endif %}
<header class="post-header">
<h1>{{ title }}</h1>
<time datetime="{{ createdAt | dateTimeFormat }}">{{ createdAt | dateTimeFormat }}</time>
<time class="localizable-time" datetime="{{ createdAt | isoDateTime }}">{{ createdAt | dateTimeFormat }}</time>
{% if updatedAt and (updatedAt | isMoreThanHourAfter(createdAt)) %}
<p class="updated-at">Updated: <time datetime="{{ updatedAt | dateTimeFormat }}">{{ updatedAt | dateTimeFormat }}</time></p>
<p class="updated-at">Updated: <time class="localizable-time" datetime="{{ updatedAt | isoDateTime }}">{{ updatedAt | dateTimeFormat }}</time></p>
{% endif %}
</header>