File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree 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 11import client from '$lib/apiClient'
2+ import { getFlatArrayUnrepeated } from '$lib/utilities' ;
23import { readSingleton , readItems } from '@directus/sdk'
34
45export async function load ( ) {
@@ -20,9 +21,13 @@ export async function load() {
2021 sort : [ '-date_published' ] ,
2122 } ) )
2223
24+ const tags = getFlatArrayUnrepeated ( posts ) ;
25+ tags . unshift ( 'todos' ) ;
26+
2327 return {
2428 blog,
25- posts
29+ posts,
30+ tags,
2631 }
2732}
2833
Original file line number Diff line number Diff line change 11<script >
22 import ArticleCard from " @/components/Cards/ArticleCard.svelte" ;
33 import BlogHero from " @/components/BlogHero.svelte" ;
4+ import MenuTagsBlog from " @/components/MenuTagsBlog.svelte" ;
45 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+ }
617 </script >
718<div class =" container my-20 mx-auto" >
819
920 <div class =" container m-auto px-3" >
1021 <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 >
1223 </div >
1324 <BlogHero
1425 slug ={blog .highlight_post .slug }
2031 content ={blog .highlight_post .content }
2132 />
2233 </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 >
2341 <div class =" container m-auto p-3" >
2442 <div class =" md:grid grid-cols-3 gap-5" >
25- {#each posts as post }
43+ {#each filteredPosts as post }
2644 <ArticleCard
2745 slug ={post .slug }
2846 title ={post .title }
You can’t perform that action at this time.
0 commit comments