@@ -3,27 +3,43 @@ import { z } from "astro:schema";
33import { getCollection , type CollectionEntry } from " astro:content" ;
44import ResourcesBySelectorReact from " ./ResourcesBySelector" ;
55
6- type Props = z .infer <typeof props >;
7- type Frontmatter = keyof CollectionEntry <" docs" >[" data" ];
6+ type Props = z .input <typeof props >;
7+
8+ type DocsData = keyof CollectionEntry <" docs" >[" data" ];
9+ type VideosData = keyof CollectionEntry <" stream" >[" data" ];
10+
11+ type ResourcesData = DocsData | VideosData ;
812
913const props = z .object ({
1014 tags: z .string ().array ().optional (),
1115 types: z .string ().array (),
1216 products: z .string ().array ().optional (),
1317 directory: z .string ().optional (),
14- filterables: z .custom <Frontmatter >().array ().optional (),
18+ filterables: z .custom <ResourcesData >().array ().optional (),
19+ columns: z .union ([z .literal (2 ), z .literal (3 )]).default (2 ),
1520});
1621
17- const { tags, types, products, directory, filterables } = props .parse (
22+ const { tags, types, products, directory, filterables, columns } = props .parse (
1823 Astro .props ,
1924);
2025
21- const resources = await getCollection (" docs" , ({ id , data }) => {
26+ const docs = await getCollection (" docs" );
27+ const videos = await getCollection (" stream" );
28+
29+ const resources: Array <CollectionEntry <" docs" > | CollectionEntry <" stream" >> = [
30+ ... docs ,
31+ ... videos ,
32+ ].filter (({ id , collection , data }) => {
33+ const type = " pcx_content_type" in data ? data .pcx_content_type : collection ;
2234 return (
23- types .includes (data . pcx_content_type ?? " " ) &&
35+ types .includes (type ?? " " ) &&
2436 (directory ? id .startsWith (directory ) : true ) &&
2537 (tags ? data .tags ?.some ((v : string ) => tags .includes (v )) : true ) &&
26- (products ? data .products ?.some ((v : string ) => products .includes (v )) : true )
38+ (products
39+ ? data .products ?.some ((v ) =>
40+ products .includes (typeof v === " object" ? v .id : v ),
41+ )
42+ : true )
2743 );
2844});
2945
@@ -32,7 +48,7 @@ const facets = resources.reduce(
3248 if (! filterables ) return acc ;
3349
3450 for (const filter of filterables ) {
35- const val = page .data [filter ];
51+ const val = page .data [filter as keyof typeof page . data ];
3652 if (val ) {
3753 if (Array .isArray (val ) && val .every ((v ) => typeof v === " string" )) {
3854 acc [filter ] = [... new Set ([... (acc [filter ] || []), ... val ])];
@@ -53,6 +69,7 @@ const facets = resources.reduce(
5369 resources ={ resources }
5470 facets ={ facets }
5571 filters ={ filterables }
72+ columns ={ columns }
5673 client:load
5774 />
5875</div >
0 commit comments