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)]; +};