From 87deddd5445080fda360e9f34cb8bd88bfbe7204 Mon Sep 17 00:00:00 2001 From: Devin Haska Date: Sat, 17 Feb 2024 12:56:42 -0800 Subject: [PATCH] feat: update catalogue to work with tags --- config/collections/index.js | 17 +++++++++++++++++ config/filters/index.js | 1 - eleventy.config.js | 8 +++++--- jsconfig.json | 2 +- src/_includes/partials/catalogue.html | 21 +++++++++++++++++++++ src/content/catalogue/games/games.json | 2 +- src/content/pages/catalogue.html | 5 +++-- 7 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 src/_includes/partials/catalogue.html diff --git a/config/collections/index.js b/config/collections/index.js index 320e8d4..3cc0c44 100644 --- a/config/collections/index.js +++ b/config/collections/index.js @@ -13,6 +13,23 @@ const postsByTag = (collection) => { return postsByTag; }; +const catalogueByType = (collection) => { + const allItems = collection.getFilteredByTag("catalogue"); + + const catalogueByType = {}; + + for (const item of allItems) { + const type = item.data.tags[1]; + if (!type) continue; + + catalogueByType[type] ??= []; + catalogueByType[type].push(item); + } + + return catalogueByType; +}; + module.exports = { postsByTag, + catalogueByType, }; diff --git a/config/filters/index.js b/config/filters/index.js index 8143685..9b34a68 100644 --- a/config/filters/index.js +++ b/config/filters/index.js @@ -4,7 +4,6 @@ const advancedFormat = require("dayjs/plugin/advancedFormat"); const postcss = require("postcss"); const cssnano = require("cssnano"); -const { default: slugify } = require("slugify"); const keys = Object.keys; const values = Object.values; diff --git a/eleventy.config.js b/eleventy.config.js index 53e7abd..c2603b7 100644 --- a/eleventy.config.js +++ b/eleventy.config.js @@ -1,4 +1,7 @@ -const { postsByTag } = require("./config/collections/index.js"); +const { + postsByTag, + catalogueByType, +} = require("./config/collections/index.js"); const { dir } = require("./config/constants.js"); const { entries, @@ -7,8 +10,6 @@ const { values, organizeByDate, keys, - filterByCategory, - allTags, allTagCounts, filter, } = require("./config/filters/index.js"); @@ -25,6 +26,7 @@ module.exports = (eleventyConfig) => { // --------------------- Custom Collections ----------------------- eleventyConfig.addCollection("postsByTag", postsByTag); + eleventyConfig.addCollection("catalogueByType", catalogueByType); // --------------------- Custom Filters ----------------------- eleventyConfig.addFilter("allTagCounts", allTagCounts); diff --git a/jsconfig.json b/jsconfig.json index 6555d57..cdee14e 100644 --- a/jsconfig.json +++ b/jsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { "module": "CommonJS", - "target": "ES6" + "target": "ES2023" }, "exclude": ["node_modules"] } diff --git a/src/_includes/partials/catalogue.html b/src/_includes/partials/catalogue.html new file mode 100644 index 0000000..ddf76c2 --- /dev/null +++ b/src/_includes/partials/catalogue.html @@ -0,0 +1,21 @@ +{% set itemsByYear = items | organizeByDate %} +{% set years = itemsByYear | keys | sort("desc") %} +
+ {% for year in years %} + {% set itemsInYear = itemsByYear[year] %} +
+

{{ year }}

+
+
+ {% for item in itemsInYear %} + {% set type = item.data.tags[1] %} +
+ {{ item.data.title }} +
+

{{ type }}

+

{{ item.date | formatDate("MM/DD") }}

+
+ {% endfor %} +
+ {% endfor %} +
diff --git a/src/content/catalogue/games/games.json b/src/content/catalogue/games/games.json index 7a121dc..3fdb03c 100644 --- a/src/content/catalogue/games/games.json +++ b/src/content/catalogue/games/games.json @@ -1,5 +1,5 @@ { "layout": "catalogue", - "tags": "games", + "tags": "game", "permalink": "games/{{ page.fileSlug }}/index.html" } diff --git a/src/content/pages/catalogue.html b/src/content/pages/catalogue.html index 32a381a..1b37c53 100644 --- a/src/content/pages/catalogue.html +++ b/src/content/pages/catalogue.html @@ -4,5 +4,6 @@ permalink: /catalogue/index.html title: Catalogue --- -

Catalogue yo

-{% for item in collections.catalogue %}{{ item.data.tags | dump }}{% endfor %} +

Catalogue

+{% set items = collections.catalogue %} +{% include "partials/catalogue.html" %}