feat: updated date formatting logic
This commit is contained in:
parent
7b5f3adee9
commit
a849a028ec
5 changed files with 8 additions and 8 deletions
|
|
@ -5,9 +5,9 @@ layout: base.njk
|
||||||
<article class="blog-post">
|
<article class="blog-post">
|
||||||
<header class="post-header">
|
<header class="post-header">
|
||||||
<h1>{{ title }}</h1>
|
<h1>{{ title }}</h1>
|
||||||
<time datetime="{{ createdAt | dateFormat }}">{{ createdAt | dateFormat }}</time>
|
<time datetime="{{ createdAt | dateTimeFormat }}">{{ createdAt | dateTimeFormat }}</time>
|
||||||
{% if updatedAt and (updatedAt | isMoreThanHourAfter(createdAt)) %}
|
{% if updatedAt and (updatedAt | isMoreThanHourAfter(createdAt)) %}
|
||||||
<p class="updated-at">Updated: <time datetime="{{ updatedAt | dateFormat }}">{{ updatedAt | dateFormat }}</time></p>
|
<p class="updated-at">Updated: <time datetime="{{ updatedAt | dateTimeFormat }}">{{ updatedAt | dateTimeFormat }}</time></p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -120,11 +120,11 @@ module.exports = (eleventyConfig) => {
|
||||||
|
|
||||||
eleventyConfig.setLibrary("md", md);
|
eleventyConfig.setLibrary("md", md);
|
||||||
|
|
||||||
eleventyConfig.addFilter("dateFormat", (date) => {
|
eleventyConfig.addFilter("dateTimeFormat", (date) => {
|
||||||
const dt = date instanceof Date
|
const dt = date instanceof Date
|
||||||
? DateTime.fromJSDate(date)
|
? DateTime.fromJSDate(date)
|
||||||
: DateTime.fromISO(date);
|
: DateTime.fromISO(date);
|
||||||
return dt.toFormat('MMMM d, yyyy');
|
return dt.toFormat('MMMM d, yyyy h:mm a');
|
||||||
});
|
});
|
||||||
|
|
||||||
eleventyConfig.addFilter("isoDate", (date) => {
|
eleventyConfig.addFilter("isoDate", (date) => {
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ title: Blog
|
||||||
<li>
|
<li>
|
||||||
<a href="{{ post.url }}" class="post-card">
|
<a href="{{ post.url }}" class="post-card">
|
||||||
<h2>{{ post.data.title }}</h2>
|
<h2>{{ post.data.title }}</h2>
|
||||||
<time datetime="{{ post.data.createdAt | dateFormat }}">{{ post.data.createdAt | dateFormat }}</time>
|
<time datetime="{{ post.data.createdAt | dateTimeFormat }}">{{ post.data.createdAt | dateTimeFormat }}</time>
|
||||||
{% if post.data.description %}
|
{% if post.data.description %}
|
||||||
<p>{{ post.data.description }}</p>
|
<p>{{ post.data.description }}</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ layout: base.njk
|
||||||
<li>
|
<li>
|
||||||
<a href="/post/{{ slugData }}/{{ post.data.createdAt | isoDate }}/" class="post-card">
|
<a href="/post/{{ slugData }}/{{ post.data.createdAt | isoDate }}/" class="post-card">
|
||||||
<h2>{{ post.data.title }}</h2>
|
<h2>{{ post.data.title }}</h2>
|
||||||
<time datetime="{{ post.data.createdAt | dateFormat }}">{{ post.data.createdAt | dateFormat }}</time>
|
<time datetime="{{ post.data.createdAt | dateTimeFormat }}">{{ post.data.createdAt | dateTimeFormat }}</time>
|
||||||
{% if post.data.description %}
|
{% if post.data.description %}
|
||||||
<p>{{ post.data.description }}</p>
|
<p>{{ post.data.description }}</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
||||||
4
tags.njk
4
tags.njk
|
|
@ -15,7 +15,7 @@ layout: base.njk
|
||||||
<li>
|
<li>
|
||||||
<a href="{{ post.url }}" class="post-card">
|
<a href="{{ post.url }}" class="post-card">
|
||||||
<h2>{{ post.data.title }}</h2>
|
<h2>{{ post.data.title }}</h2>
|
||||||
<time datetime="{{ post.date | dateFormat }}">{{ post.date | dateFormat }}</time>
|
<time datetime="{{ post.date | dateTimeFormat }}">{{ post.date | dateTimeFormat }}</time>
|
||||||
{% if post.data.description %}
|
{% if post.data.description %}
|
||||||
<p>{{ post.data.description }}</p>
|
<p>{{ post.data.description }}</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
@ -24,4 +24,4 @@ layout: base.njk
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<p><a href="/tags/"><3E> All tags</a></p>
|
<p><a href="/tags/"><3E> All tags</a></p>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue