Skip to content

Commit

Permalink
Datetime format (mmistakes#2844)
Browse files Browse the repository at this point in the history
* datetime_format

* page__meta

* page__date

* page__date test

* update docs

* update docs
  • Loading branch information
luweizheng authored Apr 13, 2021
1 parent 0e922d0 commit 892454c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
5 changes: 3 additions & 2 deletions _includes/page__date.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% assign date_format = site.date_format | default: "%B %-d, %Y" %}
{% if page.last_modified_at %}
<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>
<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>
{% elsif page.date %}
<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>
<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>
{% endif %}
3 changes: 2 additions & 1 deletion _includes/page__meta.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
{% assign date = document.date %}
<span class="page__meta-date">
<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>
<time datetime="{{ date | date_to_xmlschema }}">{{ date | date: "%B %-d, %Y" }}</time>
{% assign date_format = site.date_format | default: "%B %-d, %Y" %}
<time datetime="{{ date | date_to_xmlschema }}">{{ date | date: date_format }}</time>
</span>
{% endif %}

Expand Down
6 changes: 6 additions & 0 deletions docs/_docs/05-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,12 @@ defaults:

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

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`.

```yaml
date_format: "%Y-%m-%d"
```

### Reading time

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`.
Expand Down

0 comments on commit 892454c

Please sign in to comment.