From 7f1b5decc44c01d76fc4301bda613c52524f38d7 Mon Sep 17 00:00:00 2001 From: Jim Bumgardner Date: Wed, 17 Jul 2024 15:51:04 -0700 Subject: [PATCH] Modified get-posts to ignore null entries. --- src/js/eleventy/event-list/get-posts.js | 34 +++++++++++++------------ src/js/eleventy/post-list/get-posts.js | 2 +- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/js/eleventy/event-list/get-posts.js b/src/js/eleventy/event-list/get-posts.js index ca8d18db1d2..a76af50b342 100644 --- a/src/js/eleventy/event-list/get-posts.js +++ b/src/js/eleventy/event-list/get-posts.js @@ -1,5 +1,5 @@ const fs = require("fs"); -const config = require("../../../../config"); +const config = require("../../../../config/index.js"); /** * Checks for a match between two sets of categories. @@ -12,7 +12,7 @@ const categoryMatchBetween = (componentCategories, postCategories) => { category.replace("-", " ") ); const intersection = postCategories.filter((category) => - category != null && unsluggedCategories.includes(category.toLowerCase()) + (category != null && unsluggedCategories.includes(category.toLowerCase())) ); return intersection.length > 0; }; @@ -43,20 +43,21 @@ const getEventsByCategory = (categoryString, count = 5) => { } }); - const postsToReturn = wordPressArray - .sort((a, b) => { - try { - // @TODO TEST EVENTS - - const aDate = a.data.event.startDate; - const bDate = b.data.event.startDate; - return new Date(aDate) - new Date(bDate); - } catch (error) { - console.error("missing date value"); - return 0; // Trying no difference to skip sort values. - } - }) - .slice(-count) - .reverse(); + // this was unused + // const postsToReturn = wordPressArray + // .sort((a, b) => { + // try { + // // @TODO TEST EVENTS - + // const aDate = a.data.event.startDate; + // const bDate = b.data.event.startDate; + // return new Date(aDate) - new Date(bDate); + // } catch (error) { + // console.error("missing date value"); + // return 0; // Trying no difference to skip sort values. + // } + // }) + // .slice(-count) + // .reverse(); const today = new Date(); const tomorrow = new Date(today); @@ -72,6 +73,7 @@ const getEventsByCategory = (categoryString, count = 5) => { console.error("missing date value"); return a; } + return a; }); return postsToReturnRecent; diff --git a/src/js/eleventy/post-list/get-posts.js b/src/js/eleventy/post-list/get-posts.js index c34e7da8a83..bd961a9d155 100644 --- a/src/js/eleventy/post-list/get-posts.js +++ b/src/js/eleventy/post-list/get-posts.js @@ -11,7 +11,7 @@ const categoryMatchBetween = (componentCategories, postCategories) => { category.replace("-", " ") ); const intersection = postCategories.filter((category) => - unsluggedCategories.includes(category.toLowerCase()) + (category != null && unsluggedCategories.includes(category.toLowerCase())) ); return intersection.length > 0; };