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

View File

@ -12,6 +12,13 @@
<body class="bg-white text-gray-900 dark:bg-gray-900 dark:text-gray-100"> <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="container max-w-2xl mb-24 mt-8 mx-auto">
<div class="px-5 md:px-8"> <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"> <main id="main" class="prose lg:prose-lg dark:prose-invert">
{% block content %} {% block content %}
{% endblock content %} {% endblock content %}

View File

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

View File

@ -7,13 +7,6 @@ pagination:
{% extends 'layouts/default.njk' %} {% extends 'layouts/default.njk' %}
{% block content %} {% block content %}
{% set postslist = collections.posts %} {% 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"> <section class="h-feed">
{% for post in postslist %} {% for post in postslist %}
<article class="h-entry"> <article class="h-entry">
@ -24,7 +17,7 @@ pagination:
{{ post.excerpt | safe }} {{ post.excerpt | safe }}
</div> </div>
<time class="dt-published" datetime={{ post.published_at }} pubdate> <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> </time>
</article> </article>
{% endfor %} {% endfor %}