From ab9068c83329430c5b7fe6f2474732ba1ac38479 Mon Sep 17 00:00:00 2001 From: Neil Brommer Date: Fri, 7 Jul 2023 16:42:16 -0700 Subject: [PATCH] Add posts section --- .eleventy.js | 17 ++++++++++++----- src/_includes/layouts/layout.njk | 4 +++- src/posts/index.njk | 21 +++++++++++++++++++++ src/posts/post1.md | 8 ++++++++ src/posts/post2.md | 8 ++++++++ src/posts/posts.11tydata.json | 3 +++ 6 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 src/posts/index.njk create mode 100644 src/posts/post1.md create mode 100644 src/posts/post2.md create mode 100644 src/posts/posts.11tydata.json diff --git a/.eleventy.js b/.eleventy.js index f246a3f..98615b6 100644 --- a/.eleventy.js +++ b/.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", diff --git a/src/_includes/layouts/layout.njk b/src/_includes/layouts/layout.njk index bbd16bb..e7e38b0 100644 --- a/src/_includes/layouts/layout.njk +++ b/src/_includes/layouts/layout.njk @@ -36,10 +36,12 @@ {% set standalonePages = collections.all | filterDrafts | IsNotMainPageSection | eleventyNavigation %} {% if standalonePages | length %} +

  • {% for standalonePage in standalonePages %} -
  • + {# select the page on sub-pages #} +
  • {% if standalonePage.icon is defined %} diff --git a/src/posts/index.njk b/src/posts/index.njk new file mode 100644 index 0000000..fe6bb8e --- /dev/null +++ b/src/posts/index.njk @@ -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 %} +
    +

    {{ post.data.title }}

    +
    + {{ post.date.toLocaleDateString("en-US") }} +
    +

    {{ post.data.description }}

    + + {% endfor %} +{% else %} +

    No posts

    +{% endif %} diff --git a/src/posts/post1.md b/src/posts/post1.md new file mode 100644 index 0000000..68f8738 --- /dev/null +++ b/src/posts/post1.md @@ -0,0 +1,8 @@ +--- +title: Post 1 +description: Post 1 description +date: git Created +draft: true +--- + +Post 1 content diff --git a/src/posts/post2.md b/src/posts/post2.md new file mode 100644 index 0000000..d4b07e3 --- /dev/null +++ b/src/posts/post2.md @@ -0,0 +1,8 @@ +--- +title: Post 2 +description: Post 2 description +date: git Created +draft: true +--- + +Post 2 content diff --git a/src/posts/posts.11tydata.json b/src/posts/posts.11tydata.json new file mode 100644 index 0000000..5d113c3 --- /dev/null +++ b/src/posts/posts.11tydata.json @@ -0,0 +1,3 @@ +{ + "tags": [ "posts" ] +}