Updated date logic
This commit is contained in:
parent
93a71be8ef
commit
21185f30f1
4 changed files with 26 additions and 13 deletions
|
|
@ -8,7 +8,9 @@
|
||||||
</div>
|
</div>
|
||||||
<% } %>
|
<% } %>
|
||||||
<p><%= page.description %></p>
|
<p><%= page.description %></p>
|
||||||
<a href='<%= url_for(page.path) %>' class="page-date"><%- include('date', { date: page.date.toISOString() }) %></a>
|
<div class="date smoll">
|
||||||
|
<a href='<%= url_for(page.path) %>' class="page-date"><%- include('date', { date: page.date.toISOString() }) %></a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="post-content">
|
<div class="post-content">
|
||||||
<%- page.content %>
|
<%- page.content %>
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,20 @@
|
||||||
<div class="date smoll">
|
|
||||||
<%
|
<% {
|
||||||
const posted = new Date(date);
|
const posted = new Date(date);
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const year = 365 * 24 * 60 * 60 * 1000;
|
const day = ((d => {
|
||||||
const format = (now - posted) < year ?
|
if (d > 3 && d < 21) return d + 'th';
|
||||||
{ day: 'numeric', month: 'long', hour: 'numeric', minute: 'numeric', hour12: true } :
|
switch (d % 10) {
|
||||||
{ day: 'numeric', month: 'long', year: 'numeric', hour: 'numeric', minute: 'numeric', hour12: true };
|
case 1: return d + 'st';
|
||||||
%>
|
case 2: return d + 'nd';
|
||||||
<%= posted.toLocaleString('en-US', format ) %>
|
case 3: return d + 'rd';
|
||||||
</div>
|
default: return d + 'th';
|
||||||
|
}
|
||||||
|
})(posted.getDate()));
|
||||||
|
|
||||||
|
const options = now.getFullYear() === posted.getFullYear()
|
||||||
|
? { month: 'long', hour: 'numeric', minute: 'numeric', hour12: true }
|
||||||
|
: { year: 'numeric', month: 'long'};
|
||||||
|
%>
|
||||||
|
<%= day %> <%= posted.toLocaleString('en-US', options).replace(/^(\d+)\s/, '') %>
|
||||||
|
<% } %>
|
||||||
|
|
@ -9,7 +9,9 @@
|
||||||
<% } %>
|
<% } %>
|
||||||
<div class="post-header">
|
<div class="post-header">
|
||||||
<a href='<%= url_for(post.path) %>'><h2><%= post.title || "Untitled" %></h2>
|
<a href='<%= url_for(post.path) %>'><h2><%= post.title || "Untitled" %></h2>
|
||||||
<%- include('date', { date: post.date.toISOString() }) %></a>
|
<div class="date smoll">
|
||||||
|
<%- include('date', { date: post.date.toISOString() }) %></a>
|
||||||
|
</div>
|
||||||
<p class="post_description"><%= post.description %></p>
|
<p class="post_description"><%= post.description %></p>
|
||||||
<div class="tags smoll">
|
<div class="tags smoll">
|
||||||
<% post.tags.data.forEach(function(tag) { %>
|
<% post.tags.data.forEach(function(tag) { %>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue