Files
gitbook/src/components/DocumentView/Blocks.tsx
T
Samy Pessé 13b9f6b07f Optimize images using Cloudflare Images (#40)
* Optimize images using Cloudflare Images

* Try skipping middleware

* Make it work with base path

* Fetch image size

* Use a target instead of the cf fetch options

* Fix resizing

* Start optimizing images

* Preload images

* Use it for page cover

* Format and adapt cover

* Fix image resizing serving jpeg

* Lazy load dark mode images

* Timeout at 2s

* Fix iframe CSP

* Implement logic to lazy load images that should be offscreen

* Also lazy load cover images

* Low priority in preloading

* Fix csp
2023-12-17 22:26:07 +01:00

44 lines
1.2 KiB
TypeScript

import { DocumentBlock, JSONDocument } from '@gitbook/api';
import { tcls, ClassValue } from '@/lib/tailwind';
import { Block } from './Block';
import { DocumentContextProps } from './DocumentView';
export function Blocks<T extends DocumentBlock, Tag extends React.ElementType = 'div'>(
props: DocumentContextProps & {
/** Blocks to render */
nodes: T[];
/** Document being rendered */
document: JSONDocument;
/** Ancestors of the blocks */
ancestorBlocks: DocumentBlock[];
/** HTML tag to use */
tag?: Tag;
/** Style passed to the wrapper */
style?: ClassValue;
/** Style passed to all blocks */
blockStyle?: ClassValue;
},
) {
const { nodes, tag: Tag = 'div', style, blockStyle, ...contextProps } = props;
return (
<Tag className={tcls(style)}>
{nodes.map((node, index) => (
<Block
key={node.key}
block={node}
style={['max-w-3xl', 'w-full', 'mx-auto', 'decoration-primary/6', blockStyle]}
{...contextProps}
/>
))}
</Tag>
);
}