Skip to content

Commit

Permalink
Merge pull request #16231 from cagov/jbum-post-patch-2
Browse files Browse the repository at this point in the history
Modified get-posts to ignore null entries.
  • Loading branch information
jbum authored Jul 17, 2024
2 parents f5690ce + 7f1b5de commit f837a23
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
34 changes: 18 additions & 16 deletions src/js/eleventy/event-list/get-posts.js
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
};
Expand Down Expand Up @@ -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);
Expand All @@ -72,6 +73,7 @@ const getEventsByCategory = (categoryString, count = 5) => {
console.error("missing date value");
return a;
}
return a;
});

return postsToReturnRecent;
Expand Down
2 changes: 1 addition & 1 deletion src/js/eleventy/post-list/get-posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down

0 comments on commit f837a23

Please sign in to comment.