feat: add archive view of posts

This commit is contained in:
Devin Haska 2024-02-07 20:02:59 -08:00
parent 5e72b839fe
commit 6265474981
8 changed files with 78 additions and 10 deletions

View file

@ -0,0 +1,23 @@
{% set postsByDate = posts | entries %}
<section>
{% for postsGroupedByYear in postsByDate %}
{% set year = postsGroupedByYear | first %}
{% set postsGroupedByMonth = postsGroupedByYear | last | entries %}
{% for postsInMonth in postsGroupedByMonth %}
{% set isFirstMonthOfList = loop.index0 === 0 %}
{% set month = postsInMonth | first %}
<div class="[ flex ]">
{% if isFirstMonthOfList %}<h2>{{ year }}</h2>{% endif %}
<h2 class="[ archive-month ]">{{ month }}</h2>
</div>
{% set allPosts = postsInMonth | last %}
{% for post in allPosts %}
<div class="[ flex items-center justify-between ]">
<a href="{{ post.url }}">{{ post.data.title }}</a>
<div class="[ archive-divider ] [ mx-0.5 ]"></div>
<div>{{ post.date | formatDate("Do") }}</div>
</div>
{% endfor %}
{% endfor %}
{% endfor %}
</section>

View file

@ -0,0 +1,10 @@
.archive-divider {
border-color: var(--color-bg-faded);
border-width: 1px;
border-style: dashed;
flex: 1;
}
.archive-month {
margin-left: auto;
}

View file

@ -3,14 +3,9 @@ permalink: /posts/index.html
layout: "base"
---
{% set posts = collections.posts | organizeByDate %}
<h1>All posts</h1>
<p>
View all <a href="/tags">tags</a>
</p>
<ul>
{% for post in collections.posts %}
<li>
<a href={{ post.url }}>{{ post.data.title }}</a>
</li>
{% endfor %}
</ul>
{% include "partials/posts.html" %}

View file

@ -15,3 +15,4 @@ layout: "base"
<a href="{{ post.url }}">{{ post.data.title }}</a>
</li>
{% endfor %}
</ul>

View file

@ -0,0 +1,9 @@
---
title: Hello world again
date: 2017-02-01
categories:
- test
- email
---
This is a test post.