From dc6074e5999ae19f72ac9d53da7f9bf56f5e2afa Mon Sep 17 00:00:00 2001 From: Liron Abutbul <110838700+ladunjexa@users.noreply.github.com> Date: Fri, 9 Jun 2023 07:21:52 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20[feature]=20Add=20'findTags'=20and?= =?UTF-8?q?=20'findCategories'=20methods=20to=20blog.ts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/blog.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/utils/blog.ts b/src/utils/blog.ts index eab9735..97c1478 100644 --- a/src/utils/blog.ts +++ b/src/utils/blog.ts @@ -122,3 +122,27 @@ export const findLatestPosts = async ({ count }: { count?: number }): Promise> => { + const posts = await fetchPosts(); + const tags = posts.reduce((acc, post: Post) => { + if (post.tags && Array.isArray(post.tags)) { + return [...acc, ...post.tags]; + } + return acc; + }, []); + return [...new Set(tags)]; +}; + +/** */ +export const findCategories = async (): Promise> => { + const posts = await fetchPosts(); + const categories = posts.reduce((acc, post: Post) => { + if (post.category) { + return [...acc, post.category]; + } + return acc; + }, []); + return [...new Set(categories)]; +};