feat: add tag page
This commit is contained in:
parent
210a278ab1
commit
5e72b839fe
5 changed files with 52 additions and 3 deletions
|
@ -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,
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue