Skip to content

Commit

Permalink
Merge pull request #423 from Soroosh/date_format
Browse files Browse the repository at this point in the history
Make date format configurable
  • Loading branch information
sylhare authored Jan 15, 2024
2 parents 94b4ebb + 55e7901 commit f0614ae
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ You can find all the properties in `_data/language.yml`.

By default, it is in English, but you can easily add your own language.

Here you also can set the date format, e.g., set `str_date_format: '%B %-d, %Y'` for "January, 13, 2024", `str_date_format: '%Y-%m-%d'` for 2024-01-13, or `str_date_format: '%d.%m.%Y'` for 13.01.2024.

### Google Analytics

To enable Google Analytics (GA4), add your [Measurement ID](https://support.google.com/analytics/answer/12270356?hl=en&sjid=1593376271608310401-NA)
Expand Down
1 change: 1 addition & 0 deletions _data/language.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ str_cookie_disclaimer: "We would like to use third party cookies and scripts to
str_months: [January, February, March, April, May, June, July, August, September, October, November, December]
str_dark: 'Dark'
str_light: 'Light'
str_date_format: '%B %-d, %Y'

# Localization settings
cusdis_lang: # zh-cn, es, tr, pt-BR
2 changes: 1 addition & 1 deletion _includes/blog/post_info.liquid
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% assign author = site.data.authors[include.author] %}
{% assign date = include.date | default: "today" | date: "%B %-d, %Y" %}
{% assign date = include.date | default: "today" | date: site.data.language.str_date_format | default: '%B %-d, %Y' %}

<div class="post-info">
{%- if author.url -%}<a href="{{ author.url | relative_url }}" target="_blank" rel="noopener">{%- endif -%}
Expand Down
7 changes: 4 additions & 3 deletions _includes/default/search_input.liquid
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{% assign dateFormat = site.data.language.str_date_format | default: '%B %-d, %Y' %}
[
{% for post in site.posts %}
{
Expand All @@ -6,7 +7,7 @@
"category" : "{{ post.category }}",
"tags" : "{{ post.tags | join: ', ' | prepend: " " }}",
"url" : "{{ post.url | relative_url }}",
"date" : "{{ post.date | date: "%B %-d, %Y" }}",
"date" : "{{ post.date | date: dateFormat }}",
"excerpt" : {{ post.content | strip_html | strip_newlines | strip | escape | truncate: '250' | escape | jsonify }},
"content" : {{ post.content | strip_html | strip_newlines | strip | escape | jsonify }}
{% endunless %}
Expand All @@ -20,7 +21,7 @@
"category" : "{{ page.category }}",
"tags" : "{{ page.tags | join: ', ' | prepend: " " }}",
"url" : "{{ page.url | relative_url }}",
"date" : "{{ page.date | date: "%B %-d, %Y" | default: "N/A" }}",
"date" : "{{ page.date | date: dateFormat | default: "N/A" }}",
"excerpt" : {{ page.content | strip_html | strip_newlines | strip | escape | truncate: '250' | escape | jsonify }},
"content" : {{ page.content | strip_html | strip_newlines | strip | escape | jsonify }}
{% endunless %}
Expand All @@ -36,7 +37,7 @@
"category" : "{{ page.category }}",
"tags" : "{{ page.tags | join: ', ' | prepend: " " }}",
"url" : "{{ page.url | relative_url }}",
"date" : "{{ page.date | date: "%B %-d, %Y" | default: "N/A" }}",
"date" : "{{ page.date | date: dateFormat | default: "N/A" }}",
"excerpt" : {{ page.content | strip_html | strip_newlines | strip | escape | truncate: '250' | jsonify }},
"content" : {{ page.content | strip_html | strip_newlines | strip | escape | jsonify }}
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion _layouts/categories.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ layout: page
{% for post in site.categories[group] %}
<a href="{{ post.url | relative_url }}" class="category-post-link">
<div class="item">
<p class="meta">{{ post.date | date: "%B %-d, %Y" }}</p>
<p class="meta">{{ post.date | date: site.data.language.str_date_format | default: '%B %-d, %Y' }}</p>
<p class="title">{{ post.title }}</p>
</div>
</a>
Expand Down

0 comments on commit f0614ae

Please sign in to comment.