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 1/8] =?UTF-8?q?=E2=9C=A8=20[feature]=20Add=20'findTags'=20?= =?UTF-8?q?and=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)]; +}; From cf0d0cd0284046505bd0183082ad10f8a60b4fd3 Mon Sep 17 00:00:00 2001 From: Liron Abutbul <110838700+ladunjexa@users.noreply.github.com> Date: Fri, 9 Jun 2023 07:23:35 +0300 Subject: [PATCH 2/8] =?UTF-8?q?=F0=9F=8E=A8=20[enhancement]=20Added=20opti?= =?UTF-8?q?onal=20title=20functionality=20to=20Tags.astro?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/blog/Tags.astro | 42 +++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/src/components/blog/Tags.astro b/src/components/blog/Tags.astro index 122cd91..0990bc3 100644 --- a/src/components/blog/Tags.astro +++ b/src/components/blog/Tags.astro @@ -6,29 +6,35 @@ import type { Post } from '~/types'; export interface Props { tags: Post['tags']; - class?: string; + class?: string; + title?: string | undefined; } -const { tags, class: className = 'text-sm' } = Astro.props; +const { tags, class: className = 'text-sm', title = undefined } = Astro.props; --- { tags && Array.isArray(tags) && ( - + <> + <> + {header !== undefined && {header}} + + + ) } From dfc274228c3bb84977052f7f777256f80e13e0e8 Mon Sep 17 00:00:00 2001 From: Liron Abutbul <110838700+ladunjexa@users.noreply.github.com> Date: Fri, 9 Jun 2023 07:26:22 +0300 Subject: [PATCH 3/8] =?UTF-8?q?=F0=9F=8E=A8=20[enhancement]=20Add=20code?= =?UTF-8?q?=20to=20display=20tags=20&=20categories=20in=20the=20main=20blo?= =?UTF-8?q?g=20page?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/[...blog]/[...page].astro | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/pages/[...blog]/[...page].astro b/src/pages/[...blog]/[...page].astro index 25e057d..d6e4ce5 100644 --- a/src/pages/[...blog]/[...page].astro +++ b/src/pages/[...blog]/[...page].astro @@ -5,8 +5,10 @@ import Layout from '~/layouts/PageLayout.astro'; import BlogList from '~/components/blog/List.astro'; import Headline from '~/components/blog/Headline.astro'; import Pagination from '~/components/blog/Pagination.astro'; +// import PostTags from "~/components/blog/Tags.astro"; import { fetchPosts } from '~/utils/blog'; +// import { findTags, findCategories } from '~/utils/blog'; import { BLOG_BASE } from '~/utils/permalinks'; export async function getStaticPaths({ paginate }) { @@ -20,6 +22,9 @@ export async function getStaticPaths({ paginate }) { const { page } = Astro.props; const currentPage = page.currentPage ?? 1; +// const allCategories = await findCategories(); +// const allTags = await findTags(); + const meta = { title: `Blog${currentPage > 1 ? ` — Page ${currentPage}` : ''}`, description: SITE.description, @@ -37,5 +42,9 @@ const meta = { + From b31501845888a887ca70e1c2b8e5765ff4487fa1 Mon Sep 17 00:00:00 2001 From: Liron Abutbul <110838700+ladunjexa@users.noreply.github.com> Date: Fri, 9 Jun 2023 08:00:35 +0300 Subject: [PATCH 4/8] =?UTF-8?q?=E2=9C=85=20Fix=20typo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/blog/Tags.astro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/blog/Tags.astro b/src/components/blog/Tags.astro index 0990bc3..22453e5 100644 --- a/src/components/blog/Tags.astro +++ b/src/components/blog/Tags.astro @@ -22,7 +22,7 @@ const { tags, class: className = 'text-sm', title = undefined } = Astro.props;