File size: 1,022 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { LinkCard } from '../link-card';
import styles from './style.module.scss';

export const LinkCardList = ( { items }: { items: React.ComponentProps< typeof LinkCard >[] } ) => {
	return (
		<ul className={ styles[ 'link-card-list' ] }>
			{ items.map( ( item ) => (
				<li key={ item.href }>
					<LinkCard className={ styles[ 'link-card-list__card' ] } { ...item } />
				</li>
			) ) }
		</ul>
	);
};

export const LinkCardListFromMdx = ( {
	mdxFiles,
}: {
	/**
	 * Object of imported mdx files with metadata.
	 */
	mdxFiles: Record<
		string,
		{
			metadata: {
				permalink: string;
				title: string;
				description?: string;
				frontMatter: { image?: string };
			};
			assets: { image?: string };
		}
	>;
} ) => {
	const items = Object.values( mdxFiles ).map( ( { metadata, assets } ) => {
		return {
			href: metadata.permalink,
			label: metadata.title,
			description: metadata.description,
			image: assets.image ?? metadata.frontMatter.image,
		};
	} );
	return <LinkCardList items={ items } />;
};