add dateString filter

This commit is contained in:
James Walker 2022-11-14 21:05:03 -05:00
parent 0853782914
commit 12273058f6
Signed by: walkah
GPG Key ID: 3C127179D6086E93
4 changed files with 16 additions and 15 deletions

View File

@ -29,6 +29,10 @@ module.exports = function (eleventyConfig) {
verbose: false
});
eleventyConfig.addFilter("dateString", (dateObj) => {
return new Date(dateObj).toISOString().split("T")[0];
});
eleventyConfig.addCollection("posts", async function (collection) {
collection = await api.posts
.browse({
@ -52,7 +56,6 @@ module.exports = function (eleventyConfig) {
// Bring featured post to the top of the list
collection.sort((post, nextPost) => nextPost.featured - post.featured);
console.log(collection);
return collection;
});
}

View File

@ -12,6 +12,13 @@
<body class="bg-white text-gray-900 dark:bg-gray-900 dark:text-gray-100">
<div class="container max-w-2xl mb-24 mt-8 mx-auto">
<div class="px-5 md:px-8">
<header class="flex flex-row not-prose my-8">
<div rel="author" class="p-author h-card basis-1/2">
<a href="/">
<img class="u-photo w-8 inline-block" src="/images/walkah-avatar.png" > walkah
</a>
</div>
</header>
<main id="main" class="prose lg:prose-lg dark:prose-invert">
{% block content %}
{% endblock content %}

View File

@ -24,14 +24,12 @@
</section>
<footer class="flex flex-row not-prose">
<div rel="author" class="p-author h-card basis-1/2">
<a href="/">
<img class="u-photo w-8 inline-block" src="/images/walkah-avatar.png" > walkah
</a>
<time class="dt-published" datetime="{{ post.published_at }}" pubdate>
<a class="u-url text-gray-500 text-sm" href="{{ post.url }}">{{ post.date | dateString }}</a>
</time>
</div>
<div class="text-right basis-1/2">
<time class="dt-published" datetime="{{ post.published_at }}" pubdate>
<a class="u-url text-gray-500 text-sm" href="{{ post.url }}">{{ post.date.toLocaleDateString() }}</a>
</time>
</div>
</footer>
</article>

View File

@ -7,13 +7,6 @@ pagination:
{% extends 'layouts/default.njk' %}
{% block content %}
{% set postslist = collections.posts %}
<header class="flex flex-row not-prose">
<div rel="author" class="p-author h-card basis-1/2">
<a href="/">
<img class="u-photo w-8 inline-block" src="/images/walkah-avatar.png" > walkah
</a>
</div>
</header>
<section class="h-feed">
{% for post in postslist %}
<article class="h-entry">
@ -24,7 +17,7 @@ pagination:
{{ post.excerpt | safe }}
</div>
<time class="dt-published" datetime={{ post.published_at }} pubdate>
<a class="u-url text-gray-500 text-sm" href={{ post.url }}>{{ post.date.toLocaleDateString() }}</a>
<a class="u-url text-gray-500 text-sm" href={{ post.url }}>{{ post.date | dateString }}</a>
</time>
</article>
{% endfor %}