Add pages for tags and link to them

This commit is contained in:
Neil Brommer 2023-07-09 22:28:59 -07:00
parent 19696fad1d
commit ed004bfd8a
6 changed files with 45 additions and 21 deletions

View file

@ -11,7 +11,7 @@ layout: layouts/layout.njk
</dt> </dt>
{% for tag in tags %} {% for tag in tags %}
{% if tag != "posts" %} {% if tag != "posts" %}
<dd>{{ tag }}</dd> <dd><a href="{{ "/posts/tags/" + (tag | slugify) | url }}">{{ tag }}</a></dd>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
</dl> </dl>

View file

@ -0,0 +1,16 @@
{% if postsList | filterDrafts | IsNotPage(page.url) | length %}
{% for post in postsList | filterDrafts | reverse %}
<section>
<h2><a href={{ post.url }}>{{ post.data.title }}</a></h2>
<div>
<svg class="icon">
<use href="/images/feather-sprite.svg#clock" />
</svg>
{{ post.date.toLocaleDateString("en-US") }}
</div>
<p>{{ post.data.description }}</p>
</section>
{% endfor %}
{% else %}
<p>No posts</p>
{% endif %}

View file

@ -18,15 +18,23 @@ dl {
} }
dl.tags { dl.tags {
display: flex;
flex-direction: row;
align-items: center;
dt { dt {
display: inline-flex; display: inline-flex;
flex-direction: row; flex-direction: row;
align-items: center; align-items: center;
gap: 0.25em;
padding: 0.25em 0; padding: 0.25em 0;
}
dd { .icon {
display: inline; font-size: 1.5em;
padding-right: 0.3em;
}
&::after {
content: ":";
}
} }
} }

View file

@ -7,19 +7,5 @@ eleventyNavigation:
order: 1 order: 1
--- ---
{% if collections.posts | filterDrafts | IsNotPage(page.url) | length %} {% set postsList = collections.posts | IsNotPage(page.url) %}
{% for post in collections.posts | filterDrafts | IsNotPage(page.url) | reverse %} {% include "posts-list.njk" %}
<section>
<h2><a href={{ post.url }}>{{ post.data.title }}</a></h2>
<div>
<svg class="icon">
<use href="/images/feather-sprite.svg#clock" />
</svg>
{{ post.date.toLocaleDateString("en-US") }}
</div>
<p>{{ post.data.description }}</p>
</section>
{% endfor %}
{% else %}
<p>No posts</p>
{% endif %}

14
src/posts/tags.njk Normal file
View file

@ -0,0 +1,14 @@
---
layout: layouts/layout.njk
pagination:
data: collections
size: 1
alias: tag
filter: [ all, post, posts, MainPage ]
eleventyComputed:
title: Posts Tagged "{{ tag }}"
permalink: /posts/tags/{{ tag | slugify }}
---
{% set postsList = collections[tag] %}
{% include "posts-list.njk" %}