Update datetime metadata

It is closer to the specification at the following document:

https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-global-date-and-time-string
This commit is contained in:
Gabriel Arazas 2023-02-24 21:28:41 +08:00
parent c5b03ae623
commit d283b2babb
3 changed files with 15 additions and 8 deletions

View File

@ -24,6 +24,8 @@ and this project adheres to https://semver.org/spec/v2.0.0.html[Semantic Version
- Revert the site layout. - Revert the site layout.
- Update the datetime string for the appropriate components.

View File

@ -35,12 +35,12 @@
<!-- Only show the creation date if the `date` field is valid. --> <!-- Only show the creation date if the `date` field is valid. -->
{{- if ne (.PublishDate.Format "2006") "0001" -}} {{- if ne (.PublishDate.Format "2006") "0001" -}}
<!-- Publication date. --> <!-- Publication date. -->
<p data-content-publication-date="{{ .PublishDate }}">{{ i18n "published_on" }}: <time datetime="{{ .PublishDate.Format "2006-01-02" }}">{{ .PublishDate.Format "2006-01-02" }}</time></p> <p data-content-publication-date="{{ .PublishDate.Format "2006-01-02T15:04:05Z07:00" }}">{{ i18n "published_on" }}: <time datetime="{{ .PublishDate.Format "2006-01-02T15:04:05Z07:00" }}">{{ .PublishDate.Format "2006-01-02" }}</time></p>
{{- end }} {{- end }}
<!-- Modification date (will only appear if the publication date is less than the modified date.) --> <!-- Modification date (will only appear if the publication date is less than the modified date.) -->
{{- if ne .PublishDate .Lastmod }} {{- if ne .PublishDate .Lastmod }}
<p data-content-modification-date="{{ .Lastmod }}">{{ i18n "updated_on" }}: <time datetime="{{ .Lastmod.Format "2006-01-02" }}">{{ .Lastmod.Format "2006-01-02" }}</time></p> <p data-content-modification-date="{{ .Lastmod.Format "2006-01-02T15:04:05Z07:00" }}">{{ i18n "updated_on" }}: <time datetime="{{ .Lastmod.Format "2006-01-02T15:04:05Z07:00" }}">{{ .Lastmod.Format "2006-01-02" }}</time></p>
{{- end }} {{- end }}
<!-- Link the translated versions if the article has at least one translated page. --> <!-- Link the translated versions if the article has at least one translated page. -->

View File

@ -2,19 +2,24 @@
The component where it will display the metadata of the post. The component where it will display the metadata of the post.
This is used on list templates but feel free to change that. This is used on list templates but feel free to change that.
*/ -}} */ -}}
{{- $RFC3339 := "2006-01-02T15:04:05Z07:00" }}
<div class="list post__meta" aria-hidden="true"> <div class="list post__meta" aria-hidden="true">
{{- if ne (.PublishDate.Format "2006") "0001" -}} {{- if ne (.PublishDate.Format "2006") "0001" -}}
<time datetime="{{ .PublishDate }}" title="{{ i18n "published_on" }}"> <span>
{{ partial "components/heroicon.html" "calendar" }} {{ partial "components/heroicon.html" "calendar" }}
<span style="margin-left: 0.5em;">{{ .PublishDate.Format "2006-01-02" }}</span> <time datetime="{{ .PublishDate.Format $RFC3339 }}" title="{{ i18n "published_on" }}" style="margin-left: 0.5em;">
</time> {{ .PublishDate.Format "2006-01-02" }}
</time>
</span>
{{- end }} {{- end }}
{{- if and .GitInfo (ne (.PublishDate.Format "2006-01-02") (.Lastmod.Format "2006-01-02")) }} {{- if and .GitInfo (ne (.PublishDate.Format "2006-01-02") (.Lastmod.Format "2006-01-02")) }}
<time datetime="{{ .Lastmod }}" title="{{ i18n "updated_on" }}"> <span>
{{ partial "components/heroicon.html" "arrow-path" }} {{ partial "components/heroicon.html" "arrow-path" }}
<span style="margin-left: 0.5em;">{{ .Lastmod.Format "2006-01-02" }}</span> <time datetime="{{ .Lastmod.Format $RFC3339 }}" title="{{ i18n "updated_on" }}" style="margin-left: 0.5em;">
</time> {{ .Lastmod.Format "2006-01-02" }}
</time>
</span>
{{- end }} {{- end }}
{{- /* The authors are appended with 'et al' if there's more than one author in the map. */ -}} {{- /* The authors are appended with 'et al' if there's more than one author in the map. */ -}}