Add posts section

This commit is contained in:
Neil Brommer 2023-07-07 16:42:16 -07:00
parent 747c6d7844
commit ab9068c833
6 changed files with 55 additions and 6 deletions

View file

@ -27,7 +27,18 @@ module.exports = function (eleventyConfig) {
return collection.filter(item => !item.url || item.url.startsWith("/_sections"));
});
eleventyConfig.addFilter("IsNotMainPageSection", (collection) => {
return collection.filter(item => item.url != null && (item.data.tags == null || !item.data.tags.includes("MainPage")));
return collection.filter(item => {
if (item.url == null || item.url == false)
return false;
if (item.data.tags == null)
return true;
if (item.data.tags.includes("MainPage"))
return false;
return true;
});
});
eleventyConfig.addFilter("orderBySectionOrder", (collection) =>
collection.sort((a, b) => a.data.sectionOrder - b.data.sectionOrder)
@ -40,8 +51,6 @@ module.exports = function (eleventyConfig) {
}
return collection.filter(item => {
console.log(item);
if (item.data.draft != null) {
return !item.data.draft;
}
@ -51,8 +60,6 @@ module.exports = function (eleventyConfig) {
});
eleventyConfig.addFilter("log", (value) => console.log(value));
console.log("BUILD_DRAFTS: " + process.env.BUILD_DRAFTS);
return {
dir: {
input: "src",

View file

@ -36,10 +36,12 @@
{% set standalonePages = collections.all | filterDrafts | IsNotMainPageSection | eleventyNavigation %}
{% if standalonePages | length %}
<li><hr /></li>
{% for standalonePage in standalonePages %}
<li {% if standalonePage.url == page.url %}class="active"{% endif %}>
{# select the page on sub-pages #}
<li {% if page.url and page.url.startsWith(standalonePage.url) %}class="active"{% endif %}>
<a href="{{ standalonePage.url }}">
{% if standalonePage.icon is defined %}
<svg class="bi" fill="currentColor" role="img">

21
src/posts/index.njk Normal file
View file

@ -0,0 +1,21 @@
---
title: Posts
eleventyNavigation:
key: Posts
icon: pencil
order: 1
---
{% if collections.posts | filterDrafts | IsNotPage(page.url) | length %}
{% for post in collections.posts | filterDrafts | IsNotPage(page.url) | reverse %}
<section>
<h2><a href={{ post.url }}>{{ post.data.title }}</a></h2>
<div>
{{ post.date.toLocaleDateString("en-US") }}
</div>
<p>{{ post.data.description }}</p>
</section>
{% endfor %}
{% else %}
<p>No posts</p>
{% endif %}

8
src/posts/post1.md Normal file
View file

@ -0,0 +1,8 @@
---
title: Post 1
description: Post 1 description
date: git Created
draft: true
---
Post 1 content

8
src/posts/post2.md Normal file
View file

@ -0,0 +1,8 @@
---
title: Post 2
description: Post 2 description
date: git Created
draft: true
---
Post 2 content

View file

@ -0,0 +1,3 @@
{
"tags": [ "posts" ]
}