From c521fe58df548342b2c228ecc99ce7009befb35f Mon Sep 17 00:00:00 2001 From: luweizheng Date: Wed, 14 Apr 2021 03:58:37 +0800 Subject: [PATCH] Datetime format (#2844) * datetime_format * page__meta * page__date * page__date test * update docs * update docs --- _includes/page__date.html | 5 +++-- _includes/page__meta.html | 3 ++- docs/_docs/05-configuration.md | 6 ++++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/_includes/page__date.html b/_includes/page__date.html index e663f9b9..4f995ed0 100644 --- a/_includes/page__date.html +++ b/_includes/page__date.html @@ -1,5 +1,6 @@ +{% assign date_format = site.date_format | default: "%B %-d, %Y" %} {% if page.last_modified_at %} -

{{ site.data.ui-text[site.locale].date_label | default: "Updated:" }}

+

{{ site.data.ui-text[site.locale].date_label | default: "Updated:" }}

{% elsif page.date %} -

{{ site.data.ui-text[site.locale].date_label | default: "Updated:" }}

+

{{ site.data.ui-text[site.locale].date_label | default: "Updated:" }}

{% endif %} diff --git a/_includes/page__meta.html b/_includes/page__meta.html index 1afc3d8f..3d228c92 100644 --- a/_includes/page__meta.html +++ b/_includes/page__meta.html @@ -5,7 +5,8 @@ {% assign date = document.date %} - + {% assign date_format = site.date_format | default: "%B %-d, %Y" %} + {% endif %} diff --git a/docs/_docs/05-configuration.md b/docs/_docs/05-configuration.md index 13f3e0dd..fbd369b6 100644 --- a/docs/_docs/05-configuration.md +++ b/docs/_docs/05-configuration.md @@ -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`.