Files
gitbook/src/components/DocumentView/Embed.tsx
T
Samy Pessé 4bbd86aeca Render drawing blocks (#125)
* Improve rendering of block with captions

* Remove redirect test
2024-01-30 18:30:27 +01:00

40 lines
1.2 KiB
TypeScript

import { DocumentBlockEmbed } from '@gitbook/api';
import { Card } from '@/components/primitives';
import { api } from '@/lib/api';
import { getNodeFragmentByName, isNodeEmpty } from '@/lib/document';
import { ClassValue, tcls } from '@/lib/tailwind';
import { BlockProps } from './Block';
import { Caption } from './Caption';
import { Inlines } from './Inlines';
export async function Embed(props: BlockProps<DocumentBlockEmbed>) {
const { block } = props;
const { data: embed } = await api().urls.getEmbedByUrl({ url: block.data.url });
return (
<Caption {...props}>
{embed.type === 'rich' ? (
<div
dangerouslySetInnerHTML={{
__html: embed.html,
}}
/>
) : (
<Card
leadingIcon={
embed.icon ? (
<img src={embed.icon} className={tcls('w-5', 'h-5')} alt="Logo" />
) : null
}
href={block.data.url}
title={embed.title}
postTitle={embed.site}
/>
)}
</Caption>
);
}