-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBlocks.astro
44 lines (41 loc) · 1.37 KB
/
Blocks.astro
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
---
import type { AnyBlock } from './Blocks';
import ActionBlock from './ActionBlock/ActionBlock.astro';
import EmbedBlock from './EmbedBlock/EmbedBlock.astro';
import ImageBlock from './ImageBlock/ImageBlock.astro';
import PagePartialBlock from './PagePartialBlock/PagePartialBlock.astro';
import TableBlock from './TableBlock/TableBlock.astro';
import TextBlock from './TextBlock/TextBlock.astro';
import TextImageBlock from './TextImageBlock/TextImageBlock.astro';
import VideoBlock from './VideoBlock/VideoBlock.astro';
import VideoEmbedBlock from './VideoEmbedBlock/VideoEmbedBlock.astro';
const blocksByTypename = {
ActionBlockRecord: ActionBlock,
EmbedBlockRecord: EmbedBlock,
ImageBlockRecord: ImageBlock,
PagePartialBlockRecord: PagePartialBlock,
TableBlockRecord: TableBlock,
TextBlockRecord: TextBlock,
TextImageBlockRecord: TextImageBlock,
VideoBlockRecord: VideoBlock,
VideoEmbedBlockRecord: VideoEmbedBlock,
};
interface Props {
blocks: AnyBlock[];
}
const { blocks } = Astro.props;
---
{
blocks.map((block) => {
const typename = block.__typename as keyof typeof blocksByTypename;
const Block = blocksByTypename[typename];
return Block ? (
// @ts-ignore next line
<Block block={block} />
) : (
<script define:vars={{ typename }} is:inline>
console.log(`No Block found for "${typename}"`);
</script>
);
})
}