+ `bg-slate-200 dark:bg-slate-800 dark:hover:bg-indigo-400 hover:bg-indigo-300 hover:text-white py-1 px-4 dark:text-white rounded-full mb-2 first-letter:uppercase w-fit line-clamp-2`
+ )}
+ >
{heading.text}
{
diff --git a/src/components/Title.astro b/src/components/Title.astro
new file mode 100644
index 00000000..fb311f70
--- /dev/null
+++ b/src/components/Title.astro
@@ -0,0 +1,3 @@
+
+
+
diff --git a/src/components/TitlePage.astro b/src/components/TitlePage.astro
new file mode 100644
index 00000000..9370158a
--- /dev/null
+++ b/src/components/TitlePage.astro
@@ -0,0 +1,14 @@
+---
+import Title from './Title.astro'
+import Shape from './icons/Shape.astro'
+type Props = {
+ title: string
+}
+
+const { title } = Astro.props
+---
+
+
+
+
{title}
+
diff --git a/src/layouts/BaseLayout.astro b/src/layouts/BaseLayout.astro
index 3f1fc49e..b8cfb4f4 100644
--- a/src/layouts/BaseLayout.astro
+++ b/src/layouts/BaseLayout.astro
@@ -11,7 +11,6 @@ const { title, description, image, articleDate } = Astro.props
-
diff --git a/src/pages/category/[...category].astro b/src/pages/category/[...category].astro
index 7de0562e..18adce9c 100644
--- a/src/pages/category/[...category].astro
+++ b/src/pages/category/[...category].astro
@@ -2,8 +2,8 @@
import BaseLayout from '@/layouts/BaseLayout'
import ListPosts from '@/components/ListPosts'
import ListCategories from '@/components/ListCategories'
-import Shape from '@/components/icons/Shape'
-import { sluglify, unsluglify, getCategories, getPosts } from '@/utils'
+import TitlePage from '@/components/TitlePage'
+import { sluglify, unsluglify, getCategories, filterPostsByCategory } from '@/utils'
const { category } = Astro.params
@@ -17,21 +17,11 @@ export async function getStaticPaths() {
}
const unsluglifyNameCategory = unsluglify(category!.toLowerCase())
-
-const posts = await getPosts()
-const filterPosts = posts.filter(
- (post) => post.data.category.toLowerCase() === unsluglifyNameCategory
-)
+const filterPosts = await filterPostsByCategory(unsluglifyNameCategory)
---
-
-
-
- {unsluglifyNameCategory}
-
-
-
+
diff --git a/src/pages/index.astro b/src/pages/index.astro
index 57c587d0..e1fca0d0 100644
--- a/src/pages/index.astro
+++ b/src/pages/index.astro
@@ -1,7 +1,7 @@
---
import ListCategories from '@/components/ListCategories'
import ListPosts from '@/components/ListPosts'
-import Shape from '@/components/icons/Shape'
+import TitlePage from '@/components/TitlePage'
import BaseLayout from '@/layouts/BaseLayout'
import { getPosts } from '@/utils'
@@ -10,11 +10,7 @@ const posts = await getPosts(MAX_POSTS)
---
-
-
-
Blog title
-
-
+
diff --git a/src/pages/post/[...slug].astro b/src/pages/post/[...slug].astro
index 246bff4c..f76a678c 100644
--- a/src/pages/post/[...slug].astro
+++ b/src/pages/post/[...slug].astro
@@ -6,8 +6,8 @@ import ListRelatedPosts from '@/components/ListRelatedPosts'
import Share from '@/components/Share'
import TableOfContents from '@/components/TableOfContents'
import { getPosts } from '@/utils'
-const posts = await getCollection('blog')
+const posts = await getCollection('blog')
export async function getStaticPaths() {
const posts = await getPosts()
@@ -19,12 +19,12 @@ export async function getStaticPaths() {
type Props = CollectionEntry<'blog'>
const post = Astro.props
-
+const MAX_POSTS = 3
const getRelatedPosts = (post: Props) => {
const relatedPosts = posts.filter(
(p) => p.slug !== post.slug && p.data.tags.some((t) => post.data.tags.includes(t))
)
- return relatedPosts.slice(0, 3)
+ return relatedPosts.slice(0, MAX_POSTS)
}
const relatedPosts = getRelatedPosts(post)
@@ -42,16 +42,17 @@ const { Content, headings, remarkPluginFrontmatter } = await post.render()
-
-
+
+
diff --git a/src/pages/tags/[...tag]/index.astro b/src/pages/tags/[...tag]/index.astro
new file mode 100644
index 00000000..48da128a
--- /dev/null
+++ b/src/pages/tags/[...tag]/index.astro
@@ -0,0 +1,24 @@
+---
+import BaseLayout from '@/layouts/BaseLayout'
+import ListPosts from '@/components/ListPosts'
+import TitlePage from '@/components/TitlePage'
+import { getTags, getPostByTag } from '@/utils'
+
+export async function getStaticPaths() {
+ const tags = await getTags()
+
+ return tags.map((tag) => ({
+ params: { tag },
+ props: { tag }
+ }))
+}
+
+const { tag } = Astro.props
+
+const posts = await getPostByTag(tag)
+---
+
+
+
+
+
diff --git a/src/pages/tags/index.astro b/src/pages/tags/index.astro
index 43d16afc..8a2976b3 100644
--- a/src/pages/tags/index.astro
+++ b/src/pages/tags/index.astro
@@ -1,5 +1,22 @@
---
import BaseLayout from '@/layouts/BaseLayout'
+import TitlePage from '@/components/TitlePage'
+import { getTags } from '@/utils'
+const tags = await getTags()
---
-
tags
+
+
+
+
diff --git a/src/utils/index.ts b/src/utils/index.ts
index da2a082b..5e4a27e5 100644
--- a/src/utils/index.ts
+++ b/src/utils/index.ts
@@ -1,4 +1,4 @@
export { sluglify, unsluglify } from './sluglify'
export { cn } from './cn'
-export { getCategories, getPosts } from './post'
+export { getCategories, getPosts, getTags, getPostByTag, filterPostsByCategory } from './post'
export { remarkReadingTime } from './readTime'
diff --git a/src/utils/post.ts b/src/utils/post.ts
index 0794b5d1..0901ef2b 100644
--- a/src/utils/post.ts
+++ b/src/utils/post.ts
@@ -12,3 +12,19 @@ export const getPosts = async (max?: number) => {
.sort((a, b) => a.data.pubDate.valueOf() - b.data.pubDate.valueOf())
.slice(0, max)
}
+
+export const getTags = async () => {
+ const posts = await getCollection('blog')
+ const tags = new Set(posts.map((post) => post.data.tags).flat())
+ return Array.from(tags)
+}
+
+export const getPostByTag = async (tag: string) => {
+ const posts = await getPosts()
+ return posts.filter((post) => post.data.tags.includes(tag))
+}
+
+export const filterPostsByCategory = async (category: string) => {
+ const posts = await getPosts()
+ return posts.filter((post) => post.data.category.toLowerCase() === category)
+}