Use the same template for taglists and the blog index. Move the tagposts into a collection to make life easier
All checks were successful
Build and copy to prod / build-and-copy (push) Successful in 2m7s
All checks were successful
Build and copy to prod / build-and-copy (push) Successful in 2m7s
This commit is contained in:
parent
2a900ce835
commit
d209f82688
@ -1,10 +1,30 @@
|
|||||||
module.exports = (eleventyConfig) => {
|
module.exports = (eleventyConfig) => {
|
||||||
eleventyConfig.addCollection('tags', (collectionApi) => {
|
eleventyConfig.addCollection('tags', (collectionApi) => {
|
||||||
const tags = new Set();
|
const tags = new Set();
|
||||||
collectionApi.getAll().forEach((item) => {
|
collectionApi.getFilteredByTag("posts")
|
||||||
|
.filter(p => process.env.DEBUG || !p.data.tags.includes("draft"))
|
||||||
|
.filter(p => process.env.DEBUG || p.date < new Date())
|
||||||
|
.forEach((item) => {
|
||||||
if (!item.data.tags) return;
|
if (!item.data.tags) return;
|
||||||
item.data.tags.forEach((tag) => tags.add(tag));
|
item.data.tags.forEach((tag) => tags.add(tag));
|
||||||
});
|
});
|
||||||
return [...tags];
|
return [...tags];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
eleventyConfig.addCollection('tagPosts', (collectionApi) => {
|
||||||
|
const tagPosts = {};
|
||||||
|
collectionApi.getFilteredByTag("posts")
|
||||||
|
.filter(p => process.env.DEBUG || !p.data.tags.includes("draft"))
|
||||||
|
.filter(p => process.env.DEBUG || p.date < new Date())
|
||||||
|
.forEach((item) => {
|
||||||
|
if (!item.data.tags) return;
|
||||||
|
item.data.tags.forEach((tag) => {
|
||||||
|
if (!(tag in tagPosts)) {
|
||||||
|
tagPosts[tag] = [];
|
||||||
|
}
|
||||||
|
tagPosts[tag] = [item, ...tagPosts[tag]];
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return tagPosts;
|
||||||
|
});
|
||||||
}
|
}
|
30
src/_includes/components/blog.njk
Normal file
30
src/_includes/components/blog.njk
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<main class="wrapper-lg stack-xl">
|
||||||
|
<h1>{{ title }}</h1>
|
||||||
|
|
||||||
|
<aside class="inverse text-center">
|
||||||
|
<p class="mx-auto">
|
||||||
|
Subscribe via <a href="{{feed.rss}}">RSS</a>, <a href="{{feed.atom}}">Atom</a>, or <a href="{{feed.json}}">JSON</a>.
|
||||||
|
</p>
|
||||||
|
</aside>
|
||||||
|
|
||||||
|
<ol class="stack-xl" role='list'>
|
||||||
|
{% for item in posts %}
|
||||||
|
<li class="stack-xs">
|
||||||
|
<h2><a href="{{ item.url }}">{{ item.data.title | safe }}</a></h2>
|
||||||
|
<time class="block" datetime="{{ item.date | dateToRfc3339 }}">{{ item.date | dateDisplay }}</time>
|
||||||
|
<p class="e-content p-summary">{{ item.content | excerpt }}</p>
|
||||||
|
<a href="{{ item.url }}" class="inline-block">Read more</a>
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ol>
|
||||||
|
{% if not tag %}
|
||||||
|
<nav class="blog-nav row" data-spacing="between" aria-label="View more posts">
|
||||||
|
{% if pagination.href.next %}
|
||||||
|
<a href="{{ pagination.href.next }}">Older</a>
|
||||||
|
{% endif %}
|
||||||
|
{% if pagination.href.previous %}
|
||||||
|
<a href="{{ pagination.href.previous }}">Newer</a>
|
||||||
|
{% endif %}
|
||||||
|
</nav>
|
||||||
|
{% endif %}
|
||||||
|
</main>
|
@ -1,38 +1,18 @@
|
|||||||
---
|
---
|
||||||
title: Blog
|
title: Blog posts
|
||||||
layout: base.njk
|
layout: base.njk
|
||||||
pagination:
|
pagination:
|
||||||
data: collections.posts
|
data: collections.posts
|
||||||
size: 5
|
size: 5
|
||||||
reverse: true
|
reverse: true
|
||||||
|
alias: posts
|
||||||
eleventyImport:
|
eleventyImport:
|
||||||
collections: ["posts"]
|
collections: ["posts"]
|
||||||
|
feeds:
|
||||||
|
rss: "/rss.xml"
|
||||||
|
atom: "/atom.xml"
|
||||||
|
json: "/feed.json"
|
||||||
---
|
---
|
||||||
<main class="wrapper-lg stack-xl">
|
{% extends "components/blog.njk" %}
|
||||||
<h1>Blog posts</h1>
|
|
||||||
|
|
||||||
<aside class="inverse text-center">
|
{{ content | safe }}
|
||||||
<p>
|
|
||||||
Subscribe via <a href="/rss.xml">RSS</a>, <a href="/atom.xml">Atom</a>, or <a href="/feed.json">JSON</a>.
|
|
||||||
</p>
|
|
||||||
</aside>
|
|
||||||
|
|
||||||
<ol class="stack-xl" role='list'>
|
|
||||||
{% for item in pagination.items %}
|
|
||||||
<li class="stack-xs">
|
|
||||||
<h2><a href="{{ item.url }}">{{ item.data.title | safe }}</a></h2>
|
|
||||||
<time class="block" datetime="{{ item.date | dateToRfc3339 }}">{{ item.date | dateDisplay }}</time>
|
|
||||||
<p class="e-content p-summary">{{ item.content | excerpt }}</p>
|
|
||||||
<a href="{{ item.url }}" class="inline-block">Read more</a>
|
|
||||||
</li>
|
|
||||||
{% endfor %}
|
|
||||||
</ol>
|
|
||||||
<nav class="blog-nav row" data-spacing="between" aria-label="View more posts">
|
|
||||||
{% if pagination.href.next %}
|
|
||||||
<a href="{{ pagination.href.next }}">Older</a>
|
|
||||||
{% endif %}
|
|
||||||
{% if pagination.href.previous %}
|
|
||||||
<a href="{{ pagination.href.previous }}">Newer</a>
|
|
||||||
{% endif %}
|
|
||||||
</nav>
|
|
||||||
</main>
|
|
@ -1,6 +1,6 @@
|
|||||||
---json
|
---json
|
||||||
{
|
{
|
||||||
"title": "Blog",
|
"title": "Tagged posts",
|
||||||
"layout": "base.njk",
|
"layout": "base.njk",
|
||||||
"pagination": {
|
"pagination": {
|
||||||
"data": "collections.tags",
|
"data": "collections.tags",
|
||||||
@ -20,25 +20,9 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
---
|
---
|
||||||
|
{% extends "components/blog.njk" %}
|
||||||
|
{% set posts = collections.tagPosts[tag] %}
|
||||||
|
{% set title = "Posts tagged with “" ~ tag ~ "”" %}
|
||||||
|
{% set feeds = feed %}
|
||||||
|
|
||||||
<main class="wrapper-lg stack-xl">
|
{{ content | safe }}
|
||||||
<h1>Posts tagged “{{ tag }}”</h1>
|
|
||||||
|
|
||||||
<aside class="text-center">
|
|
||||||
<p>
|
|
||||||
Subscribe via <a href="{{ feed.rss }}">RSS</a>, <a href="{{ feed.atom }}">Atom</a>, or <a href="{{ feed.json }}">JSON</a>.
|
|
||||||
</p>
|
|
||||||
</aside>
|
|
||||||
|
|
||||||
<ol class="stack-xl" role='list'>
|
|
||||||
{% set posts = collections.posts | filterBy(tag) | reverse %}
|
|
||||||
{% for item in posts %}
|
|
||||||
<li class="stack-xs">
|
|
||||||
<h2><a href="{{ item.url }}">{{ item.data.title | safe }}</a></h2>
|
|
||||||
<time datetime="{{ item.date | dateToRfc3339 }}" class="block">{{ item.date | dateDisplay }}</time>
|
|
||||||
<div class="e-content p-summary">{{ item.content | excerpt }}</div>
|
|
||||||
<a href="{{ item.url }}" class="inline-block">Read more</a>
|
|
||||||
</li>
|
|
||||||
{% endfor %}
|
|
||||||
</ol>
|
|
||||||
</main>
|
|
||||||
|
@ -23,7 +23,7 @@ eleventyImport:
|
|||||||
<uri>{{ metadata.site.url }}</uri>
|
<uri>{{ metadata.site.url }}</uri>
|
||||||
</author>
|
</author>
|
||||||
<category term="{{ tag }}" />
|
<category term="{{ tag }}" />
|
||||||
{%- for post in collections.posts | filterBy(tag) | reverse %}
|
{%- for post in collections.tagPosts[tag] %}
|
||||||
{%- set absolutePostUrl = post.url | absoluteUrl(metadata.site.url) %}
|
{%- set absolutePostUrl = post.url | absoluteUrl(metadata.site.url) %}
|
||||||
<entry>
|
<entry>
|
||||||
<title>{{ post.data.title }}</title>
|
<title>{{ post.data.title }}</title>
|
||||||
|
@ -21,7 +21,7 @@ eleventyImport:
|
|||||||
"url": "{{ metadata.site.url }}"
|
"url": "{{ metadata.site.url }}"
|
||||||
},
|
},
|
||||||
"items": [
|
"items": [
|
||||||
{%- for post in collections.posts | filterBy(tag) | reverse %}
|
{%- for post in collections.tagPosts[tag] %}
|
||||||
{%- set absolutePostUrl = post.url | absoluteUrl(metadata.site.url) %}
|
{%- set absolutePostUrl = post.url | absoluteUrl(metadata.site.url) %}
|
||||||
{
|
{
|
||||||
"id": "{{ absolutePostUrl }}",
|
"id": "{{ absolutePostUrl }}",
|
||||||
|
@ -18,8 +18,7 @@ eleventyImport:
|
|||||||
<atom:link href="{{ permalink | absoluteUrl(metadata.site.url) }}" rel="self" type="application/rss+xml" />
|
<atom:link href="{{ permalink | absoluteUrl(metadata.site.url) }}" rel="self" type="application/rss+xml" />
|
||||||
<description>Posts tagged #{{ tag }}</description>
|
<description>Posts tagged #{{ tag }}</description>
|
||||||
<language>{{ metadata.site.language }}</language>
|
<language>{{ metadata.site.language }}</language>
|
||||||
{% set posts = collections.posts | filterBy(tag) | reverse %}
|
{%- for post in collections.tagPosts[tag] %}
|
||||||
{%- for post in posts %}
|
|
||||||
{%- set absolutePostUrl = post.url | absoluteUrl(metadata.site.url) %}
|
{%- set absolutePostUrl = post.url | absoluteUrl(metadata.site.url) %}
|
||||||
<item>
|
<item>
|
||||||
<title>{{ post.data.title }}</title>
|
<title>{{ post.data.title }}</title>
|
||||||
|
Loading…
Reference in New Issue
Block a user