Skip to content

Commit

Permalink
add datetime attributes to <time> elements (GoogleChrome#3630)
Browse files Browse the repository at this point in the history
Currently dates are marked up using `<time>` but they lack `datetime` attributes.
The HTML spec requires that the date value to be machine-readable; either the text content follows the valid date string (ISO-like patterns), or the element has the `datetime` attribute where the value is a valid date string.
https://whatwg.org/html#the-time-element

Co-authored-by: Matthias Rohmer <[email protected]>
  • Loading branch information
myakura and matthiasrohmer authored May 8, 2023
1 parent 2b2baf3 commit e54112c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions site/_includes/partials/post-headline.njk
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@
{% if date %}
<p class="type--caption color-secondary-text">
{{ 'i18n.common.published_on' | i18n(locale) }}
<time>{{ helpers.formatDateLong(date, locale) }}</time>
<time datetime="{{ helpers.formatDateNumeric(date) }}">
{{ helpers.formatDateLong(date, locale) }}
</time>
{% if updated %}
<span>•</span>
{{ 'i18n.common.updated_on' | i18n(locale) }}
<time>{{ helpers.formatDateLong(updated, locale) }}</time>
<time datetime="{{ helpers.formatDateNumeric(updated) }}">
{{ helpers.formatDateLong(updated, locale) }}
</time>
{% endif %}
</p>
{% endif %}
Expand Down
4 changes: 2 additions & 2 deletions site/_includes/partials/updated.njk
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<p class="color-secondary-text type--caption">
{% if updated %}
{{ 'i18n.common.updated_on' | i18n(locale) }} <time>{{ helpers.formatDateLong(updated, locale) }}</time>
{{ 'i18n.common.updated_on' | i18n(locale) }} <time datetime="{{ helpers.formatDateNumeric(updated) }}">{{ helpers.formatDateLong(updated, locale) }}</time>
<span>•</span>
{% elif date %}
{{ 'i18n.common.updated_on' | i18n(locale) }} <time>{{ helpers.formatDateLong(date, locale) }}</time>
{{ 'i18n.common.published_on' | i18n(locale) }} <time datetime="{{ helpers.formatDateNumeric(date) }}">{{ helpers.formatDateLong(date, locale) }}</time>
<span>•</span>
{% endif %}
<a href="{{ page.inputPath | githubLink }}">
Expand Down

0 comments on commit e54112c

Please sign in to comment.