File tree Expand file tree Collapse file tree 4 files changed +72
-4
lines changed Expand file tree Collapse file tree 4 files changed +72
-4
lines changed Original file line number Diff line number Diff line change
1
+ <script >
2
+ export let activeTag;
3
+ export let handleTags;
4
+ export let tags;
5
+ </script >
6
+
7
+ {#each tags as tag }
8
+ <a
9
+ href ={null }
10
+ class ={activeTag === tag ? ' text-cmxgreen' : null }
11
+ on:click ={() => handleTags (tag )}
12
+ >
13
+ {tag .toUpperCase ()}
14
+ </a >
15
+ {/each }
16
+
17
+ <style >
18
+ a {
19
+ display : inline-block ;
20
+ text-transform : uppercase ;
21
+ font-weight : 700 ;
22
+ line-height : 2.5 ;
23
+ }
24
+ a :not (:last-child ) {
25
+ padding-right : 15px ;
26
+ }
27
+ a :hover {
28
+ cursor : pointer ;
29
+ text-decoration : underline ;
30
+ }
31
+ </style >
Original file line number Diff line number Diff line change
1
+ const interfaceElement = [
2
+ { tags : [ '' ] }
3
+ ] ;
4
+
5
+ export function getFlatArrayUnrepeated ( elements = interfaceElement ) {
6
+ let unrepeated = [ ] ;
7
+ const setToLowerCase = ( item = '' ) => item . toLowerCase ( ) ;
8
+
9
+ elements . forEach ( item => {
10
+ unrepeated = [ ...new Set ( [ ...unrepeated , ...new Set ( item ?. tags ?. map ( setToLowerCase ) ) ] ) ]
11
+ } )
12
+
13
+ return unrepeated ;
14
+ }
Original file line number Diff line number Diff line change 1
1
import client from '$lib/apiClient'
2
+ import { getFlatArrayUnrepeated } from '$lib/utilities' ;
2
3
import { readSingleton , readItems } from '@directus/sdk'
3
4
4
5
export async function load ( ) {
@@ -20,9 +21,13 @@ export async function load() {
20
21
sort : [ '-date_published' ] ,
21
22
} ) )
22
23
24
+ const tags = getFlatArrayUnrepeated ( posts ) ;
25
+ tags . unshift ( 'todos' ) ;
26
+
23
27
return {
24
28
blog,
25
- posts
29
+ posts,
30
+ tags,
26
31
}
27
32
}
28
33
Original file line number Diff line number Diff line change 1
1
<script >
2
2
import ArticleCard from " @/components/Cards/ArticleCard.svelte" ;
3
3
import BlogHero from " @/components/BlogHero.svelte" ;
4
+ import MenuTagsBlog from " @/components/MenuTagsBlog.svelte" ;
4
5
export let data
5
- const { blog , posts } = data
6
+ const { blog , posts , tags } = data
7
+ let filteredPosts = [... posts]
8
+ let activeTag = " todos"
9
+
10
+ const handleTags = (tag = " " ) => {
11
+ tag = tag .toLocaleLowerCase ()
12
+ activeTag = tag
13
+ filteredPosts = tag === " todos"
14
+ ? [... posts]
15
+ : posts .filter (post => post .tags .map ((tagItem = ' ' ) => tagItem .toLowerCase ()).includes (tag))
16
+ }
6
17
</script >
7
18
<div class =" container my-20 mx-auto" >
8
19
9
20
<div class =" container m-auto px-3" >
10
21
<div class =" my-7" >
11
- <h1 class =" text-5xl text-cmxblack font-bold" >Blog</h1 >
22
+ <h1 class =" text-5xl text-cmxgreen font-bold" >Blog</h1 >
12
23
</div >
13
24
<BlogHero
14
25
slug ={blog .highlight_post .slug }
20
31
content ={blog .highlight_post .content }
21
32
/>
22
33
</div >
34
+ <div class =" container mx-auto px-3 pt-16 pb-12 text-center" >
35
+ <MenuTagsBlog
36
+ activeTag ={activeTag }
37
+ handleTags ={handleTags }
38
+ tags ={tags }
39
+ />
40
+ </div >
23
41
<div class =" container m-auto p-3" >
24
42
<div class =" md:grid grid-cols-3 gap-5" >
25
- {#each posts as post }
43
+ {#each filteredPosts as post }
26
44
<ArticleCard
27
45
slug ={post .slug }
28
46
title ={post .title }
You can’t perform that action at this time.
0 commit comments