@@ -16,11 +16,12 @@ export const revalidate = 3600
1616export default async function StudioIndex ( {
1717 searchParams,
1818} : {
19- searchParams : Promise < { page ?: string ; tag ?: string } >
19+ searchParams : Promise < { page ?: string ; tag ?: string ; q ?: string } >
2020} ) {
21- const { page, tag } = await searchParams
21+ const { page, tag, q } = await searchParams
2222 const pageNum = Math . max ( 1 , Number ( page || 1 ) )
2323 const perPage = 20
24+ const query = q ?. trim ( ) . toLowerCase ( ) ?? ''
2425
2526 const all = await getAllPostMeta ( )
2627
@@ -38,6 +39,22 @@ export default async function StudioIndex({
3839 }
3940 }
4041 }
42+
43+ if ( query ) {
44+ filtered = filtered . filter ( ( p ) => {
45+ const haystack = [
46+ p . title ,
47+ p . description ,
48+ ...p . tags ,
49+ p . author . name ,
50+ ...( p . authors ?. map ( ( a ) => a . name ) ?? [ ] ) ,
51+ ]
52+ . join ( ' ' )
53+ . toLowerCase ( )
54+ return haystack . includes ( query )
55+ } )
56+ }
57+
4158 const activeCategory = resolvedTag ? getCategoryById ( resolvedTag ) : null
4259
4360 const sorted = filtered . sort ( ( a , b ) => {
@@ -68,9 +85,28 @@ export default async function StudioIndex({
6885 type = 'application/ld+json'
6986 dangerouslySetInnerHTML = { { __html : JSON . stringify ( studioJsonLd ) } }
7087 />
71- { pageNum === 1 && ! tag && < StudioHero /> }
88+ { pageNum === 1 && ! tag && ! query && < StudioHero /> }
7289 < div className = 'mx-auto w-full max-w-5xl py-12' >
73- { activeCategory && (
90+ { query && (
91+ < div className = 'mb-8 flex items-center gap-3' >
92+ < span className = 'font-season text-[10px] uppercase tracking-widest text-[#666]' >
93+ Results for:
94+ </ span >
95+ < span
96+ className = 'px-2 py-0.5 font-season text-[10px] uppercase tracking-wider text-[#ECECEC]'
97+ style = { { border : '1px solid #3d3d3d' } }
98+ >
99+ { q }
100+ </ span >
101+ < Link
102+ href = '/studio'
103+ className = 'font-mono text-[10px] uppercase tracking-wider text-[#999] transition-colors hover:text-[#ECECEC]'
104+ >
105+ Clear
106+ </ Link >
107+ </ div >
108+ ) }
109+ { activeCategory && ! query && (
74110 < div className = 'mb-8 flex items-center gap-3' >
75111 < span className = 'font-mono text-[10px] uppercase tracking-widest text-[#666]' >
76112 Filtered by:
@@ -105,14 +141,16 @@ export default async function StudioIndex({
105141 < section >
106142 < h2 className = 'mb-8 flex items-center gap-2 font-mono text-[11px] uppercase tracking-widest text-[#666]' >
107143 < span className = 'inline-block h-2 w-2 bg-[#00F701]' aria-hidden = 'true' />
108- { activeCategory ? activeCategory . label : 'All Posts' }
144+ { query ? 'Search Results' : activeCategory ? activeCategory . label : 'All Posts' }
109145 </ h2 >
110146 < PostGrid posts = { feed } />
111147 </ section >
112148 ) }
113149 { pagePosts . length === 0 && (
114150 < div className = 'py-20 text-center' >
115- < p className = 'text-[14px] text-[#666]' > No posts found.</ p >
151+ < p className = 'text-[14px] text-[#666]' >
152+ { query ? `No posts matching "${ q } ".` : 'No posts found.' }
153+ </ p >
116154 < Link
117155 href = '/studio'
118156 className = 'mt-4 inline-block font-mono text-[12px] uppercase tracking-wider text-[#999] transition-colors hover:text-[#ECECEC]'
0 commit comments