From 4e0c778025234c853895ae08b9d8a59b1bac83b8 Mon Sep 17 00:00:00 2001 From: Devin Haska Date: Fri, 9 Feb 2024 20:31:48 -0800 Subject: [PATCH] feat: add catalogue page --- config/filters/index.js | 13 ++++--------- eleventy.config.js | 2 ++ src/_includes/partials/archive.html | 17 +++++++++++++++++ src/_includes/partials/posts.html | 16 ---------------- src/content/catalogue/books/a-test-book.md | 3 +++ src/content/catalogue/games/a-test-game.md | 1 + src/content/pages/catalogue.html | 4 +++- src/content/pages/posts.html | 4 ++-- 8 files changed, 32 insertions(+), 28 deletions(-) create mode 100644 src/_includes/partials/archive.html delete mode 100644 src/_includes/partials/posts.html diff --git a/config/filters/index.js b/config/filters/index.js index 46c981f..95df1d2 100644 --- a/config/filters/index.js +++ b/config/filters/index.js @@ -5,6 +5,7 @@ const advancedFormat = require("dayjs/plugin/advancedFormat"); const postcss = require("postcss"); const cssnano = require("cssnano"); +const keys = Object.keys; const values = Object.values; const entries = Object.entries; @@ -24,19 +25,12 @@ const organizeByDate = (collection) => { collection.forEach((item) => { const year = formatDate(item.date, "YYYY"); - const month = formatDate(item.date, "MMMM"); if (!collectionByDate[year]) { - return (collectionByDate[year] = { - [month]: [item], - }); + return (collectionByDate[year] = [item]); } - if (!collectionByDate[year][month]) { - return (collectionByDate[year][month] = [item]); - } - - collectionByDate[year][month].push(item); + collectionByDate[year].push(item); }); return collectionByDate; @@ -45,6 +39,7 @@ const organizeByDate = (collection) => { module.exports = { entries, formatDate, + keys, minifyCss, organizeByDate, values, diff --git a/eleventy.config.js b/eleventy.config.js index 7f716b5..a2daa55 100644 --- a/eleventy.config.js +++ b/eleventy.config.js @@ -11,6 +11,7 @@ const { minifyCss, values, organizeByDate, + keys, } = require("./config/filters/index.js"); const markdown = require("./config/plugins/markdown.js"); const imageShortcode = require("./config/shortcodes/image.js"); @@ -31,6 +32,7 @@ module.exports = (eleventyConfig) => { // --------------------- Custom Filters ----------------------- eleventyConfig.addFilter("entries", entries); eleventyConfig.addFilter("formatDate", formatDate); + eleventyConfig.addFilter("keys", keys); eleventyConfig.addFilter("minifyCss", minifyCss); eleventyConfig.addFilter("organizeByDate", organizeByDate); eleventyConfig.addFilter("values", values); diff --git a/src/_includes/partials/archive.html b/src/_includes/partials/archive.html new file mode 100644 index 0000000..dd3546d --- /dev/null +++ b/src/_includes/partials/archive.html @@ -0,0 +1,17 @@ +{% set itemsByYear = items | organizeByDate %} +{% set years = itemsByYear | keys | sort("desc") %} +
+ {% for year in years %} + {% set itemsInYear = itemsByYear[year] %} +
+

{{ year }}

+
+ {% for item in itemsInYear %} +
+ {{ item.data.title }} +
+
{{ item.date | formatDate("MM/DD") }}
+
+ {% endfor %} + {% endfor %} +
diff --git a/src/_includes/partials/posts.html b/src/_includes/partials/posts.html deleted file mode 100644 index 0a69ccd..0000000 --- a/src/_includes/partials/posts.html +++ /dev/null @@ -1,16 +0,0 @@ -
- {% for year, postsByYear in posts %} -
-

{{ year }}

-
- {% for month, postsByMonth in postsByYear %} - {% for post in postsByMonth %} -
- {{ post.data.title }} -
-
{{ post.date | formatDate("MM/DD") }}
-
- {% endfor %} - {% endfor %} - {% endfor %} -
diff --git a/src/content/catalogue/books/a-test-book.md b/src/content/catalogue/books/a-test-book.md index 1ac16fd..a20c83f 100644 --- a/src/content/catalogue/books/a-test-book.md +++ b/src/content/catalogue/books/a-test-book.md @@ -1,6 +1,9 @@ --- title: Here is my test book +subtitle: An Author date: 2023-02-02 +rating: 5 +image: https://cdn.wonderfulfrog.com/jim-butcher-peace-talks.jpeg --- Here we go!! diff --git a/src/content/catalogue/games/a-test-game.md b/src/content/catalogue/games/a-test-game.md index 734b95c..5f7e6e3 100644 --- a/src/content/catalogue/games/a-test-game.md +++ b/src/content/catalogue/games/a-test-game.md @@ -1,5 +1,6 @@ --- title: Here is my test game +subtitle: The Nintensixty date: 2024-02-08 --- diff --git a/src/content/pages/catalogue.html b/src/content/pages/catalogue.html index 7f11a1c..7ac3d4b 100644 --- a/src/content/pages/catalogue.html +++ b/src/content/pages/catalogue.html @@ -4,4 +4,6 @@ permalink: /catalogue/index.html title: Catalogue --- -Here be the catalogue page. +

Catalogue yo

+{% set items = collections.catalogue %} +{% include "partials/archive.html" %} diff --git a/src/content/pages/posts.html b/src/content/pages/posts.html index 345c5a3..dcd5891 100644 --- a/src/content/pages/posts.html +++ b/src/content/pages/posts.html @@ -4,9 +4,9 @@ layout: base title: Posts --- -{% set posts = collections.posts | organizeByDate %}

All posts

View all tags

-{% include "partials/posts.html" %} +{% set items = collections.posts %} +{% include "partials/archive.html" %}