diff --git a/config/collections/index.js b/config/collections/index.js
index d1269db..5702324 100644
--- a/config/collections/index.js
+++ b/config/collections/index.js
@@ -32,9 +32,9 @@ const getPostsByCategory = (collection) => {
const postsByCategory = {};
categories.forEach((category) => {
- const categoryPosts = posts.filter((post) =>
- post.data.categories.includes(category),
- );
+ const categoryPosts = posts.filter((post) => {
+ return post.data.categories.includes(category);
+ });
postsByCategory[category] = categoryPosts;
});
diff --git a/config/filters/index.js b/config/filters/index.js
index 668d251..cca819c 100644
--- a/config/filters/index.js
+++ b/config/filters/index.js
@@ -1,5 +1,6 @@
const dayjs = require("dayjs");
const utc = require("dayjs/plugin/utc");
+const advancedFormat = require("dayjs/plugin/advancedFormat");
const postcss = require("postcss");
const cssnano = require("cssnano");
@@ -8,6 +9,7 @@ const values = Object.values;
const entries = Object.entries;
dayjs.extend(utc);
+dayjs.extend(advancedFormat);
const minifyCss = async (css) => {
const output = await postcss([cssnano]).process(css, { from: undefined });
@@ -17,9 +19,35 @@ const minifyCss = async (css) => {
const formatDate = (date, format) => dayjs.utc(date).format(format);
+const organizeByDate = (collection) => {
+ const collectionByDate = {};
+
+ collection.forEach((item) => {
+ const year = formatDate(item.date, "YYYY");
+ const month = formatDate(item.date, "MMMM");
+
+ if (!collectionByDate[year]) {
+ return (collectionByDate[year] = {
+ [month]: [item],
+ });
+ }
+
+ if (!collectionByDate[year][month]) {
+ return (collectionByDate[year][month] = [item]);
+ }
+
+ collectionByDate[year][month].push(item);
+ });
+
+ console.log(collectionByDate);
+
+ return collectionByDate;
+};
+
module.exports = {
entries,
formatDate,
minifyCss,
+ organizeByDate,
values,
};
diff --git a/eleventy.config.js b/eleventy.config.js
index ef8c6de..83d2bca 100644
--- a/eleventy.config.js
+++ b/eleventy.config.js
@@ -9,6 +9,7 @@ const {
formatDate,
minifyCss,
values,
+ organizeByDate,
} = require("./config/filters/index.js");
const markdown = require("./config/plugins/markdown.js");
const imageShortcode = require("./config/shortcodes/image.js");
@@ -29,6 +30,7 @@ module.exports = (eleventyConfig) => {
eleventyConfig.addFilter("entries", entries);
eleventyConfig.addFilter("formatDate", formatDate);
eleventyConfig.addFilter("minifyCss", minifyCss);
+ eleventyConfig.addFilter("organizeByDate", organizeByDate);
eleventyConfig.addFilter("values", values);
// --------------------- Passthrough File Copy -----------------------
diff --git a/src/_includes/partials/posts.html b/src/_includes/partials/posts.html
new file mode 100644
index 0000000..1d36ac9
--- /dev/null
+++ b/src/_includes/partials/posts.html
@@ -0,0 +1,23 @@
+{% set postsByDate = posts | entries %}
+{{ year }}
{% endif %}
+ {{ month }}
+
View all tags
-