feat: add archive view of posts
This commit is contained in:
parent
5e72b839fe
commit
6265474981
8 changed files with 78 additions and 10 deletions
23
src/_includes/partials/posts.html
Normal file
23
src/_includes/partials/posts.html
Normal 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>
|
10
src/assets/css/blocks/archive.css
Normal file
10
src/assets/css/blocks/archive.css
Normal 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;
|
||||
}
|
|
@ -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" %}
|
||||
|
|
|
@ -15,3 +15,4 @@ layout: "base"
|
|||
<a href="{{ post.url }}">{{ post.data.title }}</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
|
9
src/content/posts/hello_world_again.md
Normal file
9
src/content/posts/hello_world_again.md
Normal file
|
@ -0,0 +1,9 @@
|
|||
---
|
||||
title: Hello world again
|
||||
date: 2017-02-01
|
||||
categories:
|
||||
- test
|
||||
- email
|
||||
---
|
||||
|
||||
This is a test post.
|
Loading…
Add table
Add a link
Reference in a new issue