Add posts section
This commit is contained in:
parent
747c6d7844
commit
ab9068c833
17
.eleventy.js
17
.eleventy.js
|
@ -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",
|
||||
|
|
|
@ -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
21
src/posts/index.njk
Normal 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
8
src/posts/post1.md
Normal 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
8
src/posts/post2.md
Normal file
|
@ -0,0 +1,8 @@
|
|||
---
|
||||
title: Post 2
|
||||
description: Post 2 description
|
||||
date: git Created
|
||||
draft: true
|
||||
---
|
||||
|
||||
Post 2 content
|
3
src/posts/posts.11tydata.json
Normal file
3
src/posts/posts.11tydata.json
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"tags": [ "posts" ]
|
||||
}
|
Loading…
Reference in a new issue