mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-23 02:53:29 +00:00
13b9f6b07f
* 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
44 lines
1.2 KiB
TypeScript
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>
|
|
);
|
|
}
|