Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[POC] Update date des articles #620

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
18 changes: 18 additions & 0 deletions .eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,24 @@ module.exports = function (eleventyConfig) {
return new Intl.DateTimeFormat(locale, options).format(date)
})

eleventyConfig.addShortcode('localizedUpdateDate', function (updateDate = null, locale = null) {
if (date === null) {
throw new Error('[localizedUpdateDate]: no date provided')
}

if (locale === null) {
throw new Error('[localizedUpdateDate]: no locale provided')
}

const options = {
day: '2-digit',
month: 'long',
year: 'numeric'
}

return new Intl.DateTimeFormat(locale, options).format(updateDate)
})

/**
* @see https://stackoverflow.com/questions/6393943/convert-javascript-string-in-dot-notation-into-an-object-reference#answer-6394168
*/
Expand Down
6 changes: 6 additions & 0 deletions src/_includes/components/ui.njk
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
{% if post.date %}
<time class="text-muted" datetime="{{ post.date.toISOString() }}">{% localizedDate post.date, locale %}</time>
{% endif %}
{% if post.updateDate %}
<time class="text-muted" datetime="{{ post.updateDate.toISOString() }}">{% localizedDate post.updateDate, locale %}</time>
{% endif %}
{% if post.data.abstract %}
<p class="my-2">{{ post.data.abstract }}</p>
{% endif %}
Expand Down Expand Up @@ -85,6 +88,9 @@
{% if displayDate == true and post.date %}
<time class="text-muted" datetime="{{ post.date.toISOString() }}">{% localizedDate post.date, locale %}</time>
{% endif %}
{% if displayDate == true and post.updateDate %}
<time class="text-muted" datetime="{{ post.updateDate.toISOString() }}">{% localizedDate post.updateDate, locale %}</time>
{% endif %}
{% if post.data.abstract %}
<p class="my-2">{{ post.data.abstract }}</p>
{% endif %}
Expand Down
9 changes: 6 additions & 3 deletions src/_includes/templates/default.njk
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
{% endif %}
<main id="main-content" class="col-md-{{ mainContentColumn }}" role="main">
{% if titleBeforeTag %}
<h1>{{ title }}</h1>
<h1>{{ title }}</h1>
{% if tags %}
<span class="visually-hidden" id="filters_label">
{{'tags.list' | translate}}
Expand All @@ -36,8 +36,11 @@
{% endfor -%}
</ul>
{% endif %}
<time class="text-muted" datetime="{{ page.date.toISOString() }}">{% localizedDate page.date, locale %}</time>
{% endif %}
<time class="text-muted" datetime="{{ page.date.toISOString() }}">{% localizedDate page.date, locale %}</time>
{% if updateDate %}
<time class="text-muted" datetime="{{ page.updateDate.toISOString() }}">{% localizedUpdateDate page.updateDate, locale %}</time>
{% endif %}
{% endif %}
<div class="mt-4">
{{ content | safe }}
</div>
Expand Down
1 change: 1 addition & 0 deletions src/fr/articles/html5-et-aria.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ title: "HTML5 & ARIA"
abstract: "Introduction HTML 5 et ARIA"
titleBeforeTag: true
date: "2016-09-16"
updateDate: "2025-01-10"
tags:
- web
- beginner
Expand Down