diff --git a/config/collections/index.js b/config/collections/index.js index 2f0e115..d17dcc8 100644 --- a/config/collections/index.js +++ b/config/collections/index.js @@ -15,24 +15,6 @@ export const postsByTag = (collection) => { return postsByTag; }; -export const gamesByYear = (collection) => { - const allGames = collection.getFilteredByTag("game"); - const gamesByYear = {}; - - allGames.forEach((game) => { - const date = new dayjs(game.date); - const year = date.year(); - - if (!gamesByYear[year]) { - gamesByYear[year] = { value: year, data: [game] }; - } else { - gamesByYear[year].data.push(game); - } - }); - - return gamesByYear; -}; - export const catalogueByType = (collection) => { const allItems = collection.getFilteredByTag("catalogue"); diff --git a/config/filters/index.js b/config/filters/index.js index a83ab01..38e5f1c 100644 --- a/config/filters/index.js +++ b/config/filters/index.js @@ -29,6 +29,22 @@ export const organizeByDate = (collection) => { return collectionByDate; }; +export const transformByDate = (collection) => { + const collectionByDate = {}; + + collection.forEach((item) => { + const year = formatDate(item.date, "YYYY"); + + if (!collectionByDate[year]) { + return (collectionByDate[year] = { value: year, data: [item] }); + } + + collectionByDate[year].data.push(item); + }); + + return collectionByDate; +}; + export const allTagCounts = (collection, ignore = ["post"]) => { if (!collection.length) { throw new Error("Invalid collection, no items"); diff --git a/eleventy.config.js b/eleventy.config.js index 11ff310..18062d5 100644 --- a/eleventy.config.js +++ b/eleventy.config.js @@ -3,11 +3,7 @@ import pluginRss from "@11ty/eleventy-plugin-rss"; import pluginNoRobots from "eleventy-plugin-no-robots"; import { eleventyImageTransformPlugin } from "@11ty/eleventy-img"; -import { - catalogueByType, - postsByTag, - gamesByYear, -} from "./config/collections/index.js"; +import { catalogueByType, postsByTag } from "./config/collections/index.js"; import { dir } from "./config/constants.js"; import { @@ -23,6 +19,7 @@ import { organizeByDate, pluralize, values, + transformByDate, } from "./config/filters/index.js"; import markdown from "./config/plugins/markdown.js"; import liteYoutube from "./config/shortcodes/youtube.js"; @@ -37,7 +34,16 @@ export default function (eleventyConfig) { eleventyConfig.addPlugin(pluginNoRobots); // --------------------- Custom Collections ----------------------- - eleventyConfig.addCollection("gamesByYear", gamesByYear); + eleventyConfig.addCollection("gamesByYear", (collection) => { + const data = collection.getFilteredByTag("game"); + const byYear = transformByDate(data); + return byYear; + }); + eleventyConfig.addCollection("booksByYear", (collection) => { + const data = collection.getFilteredByTag("book"); + const byYear = transformByDate(data); + return byYear; + }); eleventyConfig.addCollection("catalogueByType", catalogueByType); eleventyConfig.addCollection("postsByTag", postsByTag); diff --git a/src/_data/navigation.js b/src/_data/navigation.js index f8a5b29..d112dbf 100644 --- a/src/_data/navigation.js +++ b/src/_data/navigation.js @@ -17,7 +17,7 @@ export default { }, { text: "Books", - url: "/catalogue/books", + url: "/books", icon: "book", }, ], diff --git a/src/_includes/layouts/book.html b/src/_includes/layouts/book.html new file mode 100644 index 0000000..14633f5 --- /dev/null +++ b/src/_includes/layouts/book.html @@ -0,0 +1,43 @@ +--- +layout: "layouts/base" +--- + +{% from "macros/date.njk" import format %} +{% from "macros/utils.njk" import stars %} + + {% include "svgs/arrow-left.svg" %} +Back to books +
+
+ +
+
+

{{ title }}

+ {% if subtitle %}

{{ subtitle }}

{% endif %} +

+ by{{ author }} +

+ {% if rating %}{{ stars(rating) }}{% endif %} + +
+
+
+ {{ content | safe }} +
+{{ format(page.date) }} diff --git a/src/_includes/layouts/game.html b/src/_includes/layouts/game.html index ab2106f..2b25818 100644 --- a/src/_includes/layouts/game.html +++ b/src/_includes/layouts/game.html @@ -4,6 +4,9 @@ layout: "layouts/base" {% from "macros/date.njk" import format %} {% from "macros/utils.njk" import stars %} + + {% include "svgs/arrow-left.svg" %} +Back to games
@@ -14,7 +17,6 @@ layout: "layouts/base" {{ platform }}
{% if subtitle %}

{{ subtitle }}

{% endif %} - {{ format(page.date) }} {% if rating %}{{ stars(rating) }}{% endif %}