|
2 | 2 | import { updateMenuSelector } from '@/lib/menuSelectorUpdater.js'; |
3 | 3 | import ArticleCard from "@/components/Cards/ArticleCard.svelte"; |
4 | 4 | import BlogHero from "@/components/BlogHero.svelte"; |
| 5 | + import MenuTagsBlog from "@/components/MenuTagsBlog.svelte"; |
5 | 6 | export let data |
6 | | - const { blog, posts } = data |
| 7 | + const { blog, posts, tags } = data |
| 8 | + let filteredPosts = [...posts] |
| 9 | + let activeTag = "todos" |
| 10 | +
|
| 11 | + const handleTags = (tag = "") => { |
| 12 | + tag = tag.toLocaleLowerCase() |
| 13 | + activeTag = tag |
| 14 | + filteredPosts = tag === "todos" |
| 15 | + ? [...posts] |
| 16 | + : posts.filter(post => post.tags.map((tagItem = '') => tagItem.toLowerCase()).includes(tag)) |
| 17 | + } |
7 | 18 |
|
8 | 19 | updateMenuSelector({url: '/blog', color: 'text-cmxgreen'}) |
9 | 20 | </script> |
10 | 21 | <div class="container my-20 pt-hero mx-auto"> |
11 | 22 |
|
12 | 23 | <div class="container m-auto px-3"> |
13 | 24 | <div class="my-7"> |
14 | | - <h1 class="text-5xl text-cmxblack font-bold">Blog</h1> |
| 25 | + <h1 class="text-5xl text-cmxgreen font-bold">Blog</h1> |
15 | 26 | </div> |
16 | 27 | <BlogHero |
17 | 28 | slug={blog.highlight_post.slug} |
|
23 | 34 | content={blog.highlight_post.content} |
24 | 35 | /> |
25 | 36 | </div> |
| 37 | + <div class="container mx-auto px-3 pt-16 pb-12 text-center"> |
| 38 | + <MenuTagsBlog |
| 39 | + activeTag={activeTag} |
| 40 | + handleTags={handleTags} |
| 41 | + tags={tags} |
| 42 | + /> |
| 43 | + </div> |
26 | 44 | <div class="container m-auto p-3"> |
27 | 45 | <div class="md:grid grid-cols-3 gap-5"> |
28 | | - {#each posts as post} |
| 46 | + {#each filteredPosts as post} |
29 | 47 | <ArticleCard |
30 | 48 | slug={post.slug} |
31 | 49 | title={post.title} |
|
0 commit comments