From aa23becd14391432195257c05466b200396b7583 Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Thu, 23 Jul 2020 22:23:31 +0800 Subject: [PATCH] Split post date format code snippets. Code improvement --- _data/date_format.yml | 4 +++- _includes/related-posts.html | 5 +---- _includes/timeago.html | 27 +++++++++++++++++++++++++++ _layouts/category.html | 2 +- _layouts/home.html | 7 ++----- _layouts/post.html | 13 ++----------- _layouts/tag.html | 2 +- 7 files changed, 37 insertions(+), 23 deletions(-) create mode 100644 _includes/timeago.html diff --git a/_data/date_format.yml b/_data/date_format.yml index 3040be7..0a984ff 100644 --- a/_data/date_format.yml +++ b/_data/date_format.yml @@ -6,4 +6,6 @@ tooltip: "%a, %b %e, %Y, %l:%M %p %z" -post: "%b %e, %Y" \ No newline at end of file +post: + long: "%b %e, %Y" + short: "%b %e" diff --git a/_includes/related-posts.html b/_includes/related-posts.html index bfe4e49..fa256f3 100644 --- a/_includes/related-posts.html +++ b/_includes/related-posts.html @@ -93,10 +93,7 @@
diff --git a/_includes/timeago.html b/_includes/timeago.html new file mode 100644 index 0000000..b6b7bcd --- /dev/null +++ b/_includes/timeago.html @@ -0,0 +1,27 @@ + + + + {% assign this_year = site.time | date: "%Y" %} + {% assign post_year = include.date | date: "%Y" %} + + {% if post_year == this_year %} + {{ include.date | date: site.data.date_format.post.short }} + {% else %} + {{ include.date | date: site.data.date_format.post.long }} + {% endif %} + + {{ include.date | date_to_xmlschema }} + + \ No newline at end of file diff --git a/_layouts/category.html b/_layouts/category.html index a53aff5..70fec40 100644 --- a/_layouts/category.html +++ b/_layouts/category.html @@ -18,7 +18,7 @@ layout: page