Skip to content

Commit c521fe5

Browse files
authoredApr 13, 2021
Datetime format (mmistakes#2844)
* datetime_format * page__meta * page__date * page__date test * update docs * update docs
1 parent 2e05b85 commit c521fe5

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed
 

‎_includes/page__date.html

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
{% assign date_format = site.date_format | default: "%B %-d, %Y" %}
12
{% if page.last_modified_at %}
2-
<p class="page__date"><strong><i class="fas fa-fw fa-calendar-alt" aria-hidden="true"></i> {{ site.data.ui-text[site.locale].date_label | default: "Updated:" }}</strong> <time datetime="{{ page.last_modified_at | date: "%Y-%m-%d" }}">{{ page.last_modified_at | date: "%B %-d, %Y" }}</time></p>
3+
<p class="page__date"><strong><i class="fas fa-fw fa-calendar-alt" aria-hidden="true"></i> {{ site.data.ui-text[site.locale].date_label | default: "Updated:" }}</strong> <time datetime="{{ page.last_modified_at | date: "%Y-%m-%d" }}">{{ page.last_modified_at | date: date_format }}</time></p>
34
{% elsif page.date %}
4-
<p class="page__date"><strong><i class="fas fa-fw fa-calendar-alt" aria-hidden="true"></i> {{ site.data.ui-text[site.locale].date_label | default: "Updated:" }}</strong> <time datetime="{{ page.date | date_to_xmlschema }}">{{ page.date | date: "%B %-d, %Y" }}</time></p>
5+
<p class="page__date"><strong><i class="fas fa-fw fa-calendar-alt" aria-hidden="true"></i> {{ site.data.ui-text[site.locale].date_label | default: "Updated:" }}</strong> <time datetime="{{ page.date | date_to_xmlschema }}">{{ page.date | date: date_format }}</time></p>
56
{% endif %}

‎_includes/page__meta.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
{% assign date = document.date %}
66
<span class="page__meta-date">
77
<i class="far {% if include.type == 'grid' and document.read_time and document.show_date %}fa-fw {% endif %}fa-calendar-alt" aria-hidden="true"></i>
8-
<time datetime="{{ date | date_to_xmlschema }}">{{ date | date: "%B %-d, %Y" }}</time>
8+
{% assign date_format = site.date_format | default: "%B %-d, %Y" %}
9+
<time datetime="{{ date | date_to_xmlschema }}">{{ date | date: date_format }}</time>
910
</span>
1011
{% endif %}
1112

‎docs/_docs/05-configuration.md

+6
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,12 @@ defaults:
285285

286286
To disable post date for a post, add `show_date: false` to its YAML Front Matter, overriding what was set in `_config.yml`.
287287

288+
When dates are shown on blog posts or pages, a date format will be chosen to format the date string. The default format is `"%B %-d, %Y"`, which will be displayed like "February 24, 2016". You can choose your date format by referencing this [cheat sheet](https://www.shortcutfoo.com/app/dojos/ruby-date-format-strftime/cheatsheet). For example, use your date format in `_config.yml`.
289+
290+
```yaml
291+
date_format: "%Y-%m-%d"
292+
```
293+
288294
### Reading time
289295

290296
Enable estimated reading time snippets with `read_time: true` in YAML Front Matter. `200` has been set as the default words per minute value --- which can be changed by adjusting `words_per_minute:` in `_config.yml`.

0 commit comments

Comments
 (0)
Please sign in to comment.