feat: add tag page

This commit is contained in:
Devin Haska 2024-02-07 10:26:55 -08:00
parent 210a278ab1
commit 5e72b839fe
5 changed files with 52 additions and 3 deletions

View file

@ -26,7 +26,24 @@ const getAllPostCategories = (collection) => {
return categories;
};
const getPostsByCategory = (collection) => {
const posts = getAllPosts(collection);
const categories = Object.keys(getAllPostCategories(collection));
const postsByCategory = {};
categories.forEach((category) => {
const categoryPosts = posts.filter((post) =>
post.data.categories.includes(category),
);
postsByCategory[category] = categoryPosts;
});
return postsByCategory;
};
module.exports = {
getAllPosts,
getAllPostCategories,
getPostsByCategory,
};