@@ -155,10 +164,12 @@ export default async function PDFHTMLOutput(props: {
}
/>
- {pdfParams.only ? null :
}
+ {pdfParams.only ? null : (
+
+ )}
{pages.map(({ page }) =>
page.type === 'group' ? (
-
+
) : (
}
>
-
+
),
)}
@@ -227,12 +227,12 @@ async function PDFPageGroup(props: { space: Space; page: RevisionPageGroup }) {
}
async function PDFPageDocument(props: {
- space: Space;
page: RevisionPageDocument;
- refContext: ContentRefContext;
+ context: GitBookSpaceContext;
}) {
- const { space, page, refContext } = props;
- const document = await getPageDocument(space.id, page);
+ const { page, context } = props;
+ const { space } = context;
+ const document = await getPageDocument(context.dataFetcher, space.id, page);
return (
@@ -248,12 +248,10 @@ async function PDFPageDocument(props: {
blockStyle="max-w-full"
context={{
mode: 'print',
- content: {
- spaceId: space.id,
- revisionId: refContext.revisionId,
+ contentContext: {
+ ...context,
+ page,
},
- contentRefContext: refContext,
- resolveContentRef: (ref) => resolveContentRef(ref, refContext),
getId: (id) => getPagePDFContainerId(page, id),
}}
/>
diff --git a/packages/gitbook/src/app/middleware/(space)/~gitbook/pdf/pointer.ts b/packages/gitbook/src/app/middleware/(space)/~gitbook/pdf/pointer.ts
index c1d28c328..0785006e9 100644
--- a/packages/gitbook/src/app/middleware/(space)/~gitbook/pdf/pointer.ts
+++ b/packages/gitbook/src/app/middleware/(space)/~gitbook/pdf/pointer.ts
@@ -1,5 +1,8 @@
+import { GitBookSiteContext, GitBookSpaceContext } from '@v2/lib/context';
+
import { SiteContentPointer, SpaceContentPointer } from '@/lib/api';
import { getSiteContentPointer, getSpacePointer } from '@/lib/pointer';
+import { fetchV1ContextForSitePointer, fetchV1ContextForSpacePointer } from '@/lib/v1';
/**
* PDF generation can be done at the site level (e.g. docs.foo.com/~gitbook/pdf) or
@@ -17,3 +20,14 @@ export async function getSiteOrSpacePointerForPDF(): Promise<
return getSpacePointer();
}
}
+
+/**
+ * Get the context for the PDF pointer.
+ */
+export async function getV1ContextForPDF(): Promise {
+ const pointer = await getSiteOrSpacePointerForPDF();
+
+ return 'siteId' in pointer && pointer.siteId
+ ? await fetchV1ContextForSitePointer(pointer)
+ : await fetchV1ContextForSpacePointer(pointer);
+}
diff --git a/packages/gitbook/src/components/AdminToolbar/AdminToolbar.tsx b/packages/gitbook/src/components/AdminToolbar/AdminToolbar.tsx
index 9b9109b5b..849fa4cbe 100644
--- a/packages/gitbook/src/components/AdminToolbar/AdminToolbar.tsx
+++ b/packages/gitbook/src/components/AdminToolbar/AdminToolbar.tsx
@@ -1,9 +1,8 @@
-import { Space } from '@gitbook/api';
import { Icon } from '@gitbook/icons';
+import { GitBookSiteContext } from '@v2/lib/context';
import { headers } from 'next/headers';
import React from 'react';
-import { getChangeRequest, getRevision, SiteContentPointer } from '@/lib/api';
import { tcls } from '@/lib/tailwind';
import { RefreshChangeRequestButton } from './RefreshChangeRequestButton';
@@ -11,8 +10,7 @@ import { Toolbar, ToolbarBody, ToolbarButton, ToolbarButtonGroups } from './Tool
import { DateRelative } from '../primitives';
interface AdminToolbarProps {
- content: SiteContentPointer;
- space: Space;
+ context: GitBookSiteContext;
}
function ToolbarLayout(props: { children: React.ReactNode }) {
@@ -48,7 +46,7 @@ function ToolbarLayout(props: { children: React.ReactNode }) {
* Toolbar with information for the content admin when previewing a revision or change-request.
*/
export async function AdminToolbar(props: AdminToolbarProps) {
- const { content } = props;
+ const { context } = props;
const mode = await headers().get('x-gitbook-mode');
if (mode === 'multi-id') {
@@ -56,26 +54,20 @@ export async function AdminToolbar(props: AdminToolbarProps) {
return null;
}
- if (content.changeRequestId) {
- return (
-
- );
+ if (context.changeRequest) {
+ return ;
}
- if (content.revisionId) {
- return ;
+ if (context.revisionId !== context.space.revision) {
+ return ;
}
return null;
}
-async function ChangeRequestToolbar(props: { spaceId: string; changeRequestId: string }) {
- const { spaceId, changeRequestId } = props;
-
- const changeRequest = await getChangeRequest(spaceId, changeRequestId);
+async function ChangeRequestToolbar(props: { context: GitBookSiteContext }) {
+ const { context } = props;
+ const { space, changeRequest } = context;
if (!changeRequest) {
return null;
@@ -100,8 +92,8 @@ async function ChangeRequestToolbar(props: { spaceId: string; changeRequestId: s
@@ -111,10 +103,13 @@ async function ChangeRequestToolbar(props: { spaceId: string; changeRequestId: s
);
}
-async function RevisionToolbar(props: { spaceId: string; revisionId: string }) {
- const { spaceId, revisionId } = props;
+async function RevisionToolbar(props: { context: GitBookSiteContext }) {
+ const { context } = props;
+ const { space, revisionId } = context;
- const revision = await getRevision(spaceId, revisionId, {
+ const revision = await context.dataFetcher.getRevision({
+ spaceId: space.id,
+ revisionId,
metadata: true,
});
diff --git a/packages/gitbook/src/components/Ads/AdClassicRendering.tsx b/packages/gitbook/src/components/Ads/AdClassicRendering.tsx
index d33462b42..514d1dd9d 100644
--- a/packages/gitbook/src/components/Ads/AdClassicRendering.tsx
+++ b/packages/gitbook/src/components/Ads/AdClassicRendering.tsx
@@ -1,7 +1,8 @@
import { SiteInsightsAd } from '@gitbook/api';
+import { GitBookBaseContext } from '@v2/lib/context';
+import { getResizedImageURL } from '@v2/lib/images';
import * as React from 'react';
-import { getResizedImageURL } from '@/lib/images';
import { tcls } from '@/lib/tailwind';
import { AdItem } from './types';
@@ -13,14 +14,20 @@ import { Link } from '../primitives';
export async function AdClassicRendering({
ad,
insightsAd,
+ context,
}: {
ad: AdItem;
insightsAd: SiteInsightsAd | null;
+ context: GitBookBaseContext;
}) {
const smallImgSrc =
- 'smallImage' in ad ? await getResizedImageURL(ad.smallImage, { width: 192, dpr: 2 }) : null;
+ 'smallImage' in ad
+ ? await getResizedImageURL(context.imageResizer, ad.smallImage, { width: 192, dpr: 2 })
+ : null;
const logoSrc =
- 'logo' in ad ? await getResizedImageURL(ad.logo, { width: 192 - 48, dpr: 2 }) : null;
+ 'logo' in ad
+ ? await getResizedImageURL(context.imageResizer, ad.logo, { width: 192 - 48, dpr: 2 })
+ : null;
return (
{mode === 'classic' || !('callToAction' in ad) ? (
-
+
) : (
-
+
)}
{ad.pixel ? : null}
>
diff --git a/packages/gitbook/src/components/DocumentView/Block.tsx b/packages/gitbook/src/components/DocumentView/Block.tsx
index d38553bf3..dea92c573 100644
--- a/packages/gitbook/src/components/DocumentView/Block.tsx
+++ b/packages/gitbook/src/components/DocumentView/Block.tsx
@@ -96,10 +96,6 @@ export function Block(props: BlockProps) {
return ;
case 'content-ref':
return ;
- case 'image':
- case 'code-line':
- case 'tabs-item':
- throw new Error('Blocks should be directly rendered by parent');
case 'integration':
return ;
case 'reusable-content':
@@ -108,6 +104,10 @@ export function Block(props: BlockProps) {
return ;
case 'stepper-step':
return ;
+ case 'image':
+ case 'code-line':
+ case 'tabs-item':
+ throw new Error(`Blocks (${block.type}) should be directly rendered by parent`);
default:
return nullIfNever(block);
}
@@ -149,6 +149,7 @@ export function BlockSkeleton(props: { block: DocumentBlock; style: ClassValue }
case 'code':
case 'hint':
case 'tabs':
+ case 'stepper-step':
return ;
case 'expandable':
case 'table':
@@ -167,8 +168,7 @@ export function BlockSkeleton(props: { block: DocumentBlock; style: ClassValue }
case 'image':
case 'code-line':
case 'tabs-item':
- case 'stepper-step':
- throw new Error('Blocks should be directly rendered by parent');
+ throw new Error(`Blocks (${block.type}) should be directly rendered by parent`);
default:
return nullIfNever(block);
}
diff --git a/packages/gitbook/src/components/DocumentView/BlockContentRef.tsx b/packages/gitbook/src/components/DocumentView/BlockContentRef.tsx
index 98952eef6..a2b18278b 100644
--- a/packages/gitbook/src/components/DocumentView/BlockContentRef.tsx
+++ b/packages/gitbook/src/components/DocumentView/BlockContentRef.tsx
@@ -1,28 +1,28 @@
import { DocumentBlockContentRef, SiteInsightsLinkPosition } from '@gitbook/api';
import { Card } from '@/components/primitives';
-import { getSpaceCustomization, ignoreAPIError } from '@/lib/api';
-import { ResolvedContentRef } from '@/lib/references';
+import { resolveContentRef, ResolvedContentRef } from '@/lib/references';
import { BlockProps } from './Block';
-import { SpaceIcon } from '../Space/SpaceIcon';
export async function BlockContentRef(props: BlockProps) {
const { block, context, style } = props;
- const resolved = await context.resolveContentRef(block.data.ref, {
- resolveAnchorText: true,
- iconStyle: ['text-xl', 'text-tint'],
- });
+ const resolved = context.contentContext
+ ? await resolveContentRef(block.data.ref, context.contentContext, {
+ resolveAnchorText: true,
+ iconStyle: ['text-xl', 'text-tint'],
+ })
+ : null;
if (!resolved) {
return null;
}
const isContentInOtherSpace =
- context.contentRefContext?.space &&
+ context.contentContext?.space &&
'space' in block.data.ref &&
- context.contentRefContext.space.id !== block.data.ref.space;
+ context.contentContext.space.id !== block.data.ref.space;
const kind = block?.data?.ref?.kind;
if ((resolved.active && kind === 'space') || isContentInOtherSpace) {
return ;
@@ -49,28 +49,14 @@ async function SpaceRefCard(
props: { resolved: ResolvedContentRef } & BlockProps,
) {
const { context, style, resolved } = props;
- const spaceId = context.contentRefContext?.space.id;
+ const spaceId = context.contentContext?.space.id;
if (!spaceId) {
return null;
}
- const { customization: spaceCustomization } = await getSpaceCustomization();
- const customFavicon = spaceCustomization?.favicon;
- const customEmoji = customFavicon && 'emoji' in customFavicon ? customFavicon.emoji : undefined;
- const customIcon = customFavicon && 'icon' in customFavicon ? customFavicon.icon : undefined;
-
return (
- }
href={resolved.href}
title={resolved.text}
postTitle={resolved.subText}
diff --git a/packages/gitbook/src/components/DocumentView/CodeBlock/PlainCodeBlock.tsx b/packages/gitbook/src/components/DocumentView/CodeBlock/PlainCodeBlock.tsx
index 48fdb7958..87f181d94 100644
--- a/packages/gitbook/src/components/DocumentView/CodeBlock/PlainCodeBlock.tsx
+++ b/packages/gitbook/src/components/DocumentView/CodeBlock/PlainCodeBlock.tsx
@@ -48,8 +48,6 @@ export function PlainCodeBlock(props: { code: string; syntax: string }) {
document={document}
context={{
mode: 'default',
- contentRefContext: null,
- resolveContentRef: async () => null,
}}
block={block}
ancestorBlocks={[]}
diff --git a/packages/gitbook/src/components/DocumentView/DocumentView.tsx b/packages/gitbook/src/components/DocumentView/DocumentView.tsx
index 6ddcb8333..793a7264e 100644
--- a/packages/gitbook/src/components/DocumentView/DocumentView.tsx
+++ b/packages/gitbook/src/components/DocumentView/DocumentView.tsx
@@ -1,7 +1,7 @@
import { ContentRef, JSONDocument } from '@gitbook/api';
+import { GitBookAnyContext } from '@v2/lib/context';
-import { ContentTarget } from '@/lib/api';
-import { ContentRefContext, ResolveContentRefOptions, ResolvedContentRef } from '@/lib/references';
+import { ResolveContentRefOptions, ResolvedContentRef } from '@/lib/references';
import { ClassValue } from '@/lib/tailwind';
import { BlockSkeleton } from './Block';
@@ -16,22 +16,9 @@ export interface DocumentContext {
/**
* Space content being rendered.
- */
- content?: ContentTarget;
-
- /**
- * The context for resolving content refs.
* If null, content refs cannot be resolved.
*/
- contentRefContext: ContentRefContext | null;
-
- /**
- * Resolve a content reference.
- */
- resolveContentRef: (
- ref: ContentRef,
- options?: ResolveContentRefOptions,
- ) => Promise;
+ contentContext?: GitBookAnyContext;
/**
* Transform an ID to be added to the DOM.
diff --git a/packages/gitbook/src/components/DocumentView/Drawing.tsx b/packages/gitbook/src/components/DocumentView/Drawing.tsx
index 1b0d83d40..a35fd299e 100644
--- a/packages/gitbook/src/components/DocumentView/Drawing.tsx
+++ b/packages/gitbook/src/components/DocumentView/Drawing.tsx
@@ -1,5 +1,7 @@
import { DocumentBlockDrawing } from '@gitbook/api';
+import { resolveContentRef } from '@/lib/references';
+
import { BlockProps } from './Block';
import { Caption } from './Caption';
import { imageBlockSizes } from './Images';
@@ -8,7 +10,10 @@ import { Image } from '../utils';
export async function Drawing(props: BlockProps) {
const { block, context } = props;
- const resolved = block.data.ref ? await context.resolveContentRef(block.data.ref) : null;
+ const resolved =
+ block.data.ref && context.contentContext
+ ? await resolveContentRef(block.data.ref, context.contentContext)
+ : null;
if (!resolved) {
return null;
}
@@ -22,6 +27,7 @@ export async function Drawing(props: BlockProps) {
size: resolved.file?.dimensions,
},
}}
+ resize={context.contentContext?.imageResizer}
alt="Drawing"
sizes={imageBlockSizes}
zoom
diff --git a/packages/gitbook/src/components/DocumentView/Embed.tsx b/packages/gitbook/src/components/DocumentView/Embed.tsx
index 09e55ac37..8da031c1b 100644
--- a/packages/gitbook/src/components/DocumentView/Embed.tsx
+++ b/packages/gitbook/src/components/DocumentView/Embed.tsx
@@ -17,8 +17,8 @@ export async function Embed(props: BlockProps) {
ReactDOM.preload('https://cdn.iframe.ly/embed.js', { as: 'script', nonce });
- const embed = await (context.content
- ? getEmbedByUrlInSpace(context.content.spaceId, block.data.url)
+ const embed = await (context.contentContext?.space
+ ? getEmbedByUrlInSpace(context.contentContext.space.id, block.data.url)
: getEmbedByUrl(block.data.url));
return (
diff --git a/packages/gitbook/src/components/DocumentView/File.tsx b/packages/gitbook/src/components/DocumentView/File.tsx
index 30e62e050..25262a799 100644
--- a/packages/gitbook/src/components/DocumentView/File.tsx
+++ b/packages/gitbook/src/components/DocumentView/File.tsx
@@ -1,6 +1,7 @@
import { DocumentBlockFile, SiteInsightsLinkPosition } from '@gitbook/api';
import { getSimplifiedContentType } from '@/lib/files';
+import { resolveContentRef } from '@/lib/references';
import { tcls } from '@/lib/tailwind';
import { BlockProps } from './Block';
@@ -11,7 +12,9 @@ import { Link } from '../primitives';
export async function File(props: BlockProps) {
const { block, context } = props;
- const contentRef = await context.resolveContentRef(block.data.ref);
+ const contentRef = context.contentContext
+ ? await resolveContentRef(block.data.ref, context.contentContext)
+ : null;
const file = contentRef?.file;
if (!file) {
diff --git a/packages/gitbook/src/components/DocumentView/Images.tsx b/packages/gitbook/src/components/DocumentView/Images.tsx
index 063042a26..e447e517b 100644
--- a/packages/gitbook/src/components/DocumentView/Images.tsx
+++ b/packages/gitbook/src/components/DocumentView/Images.tsx
@@ -6,6 +6,7 @@ import {
} from '@gitbook/api';
import { Image, ImageResponsiveSize } from '@/components/utils';
+import { resolveContentRef } from '@/lib/references';
import { ClassValue, tcls } from '@/lib/tailwind';
import { BlockProps } from './Block';
@@ -70,8 +71,10 @@ async function ImageBlock(props: {
const { block, context, isEstimatedOffscreen } = props;
const [src, darkSrc] = await Promise.all([
- context.resolveContentRef(block.data.ref),
- block.data.refDark ? context.resolveContentRef(block.data.refDark) : null,
+ context.contentContext ? resolveContentRef(block.data.ref, context.contentContext) : null,
+ block.data.refDark && context.contentContext
+ ? resolveContentRef(block.data.refDark, context.contentContext)
+ : null,
]);
if (!src) {
@@ -83,6 +86,7 @@ async function ImageBlock(props: {
) {
const { size = 'original' } = inline.data;
const [src, darkSrc] = await Promise.all([
- context.resolveContentRef(inline.data.ref),
- inline.data.refDark ? context.resolveContentRef(inline.data.refDark) : null,
+ context.contentContext ? resolveContentRef(inline.data.ref, context.contentContext) : null,
+ inline.data.refDark && context.contentContext
+ ? resolveContentRef(inline.data.refDark, context.contentContext)
+ : null,
]);
if (!src) {
@@ -22,7 +24,7 @@ export async function InlineImage(props: InlineProps) {
}
const isInLink = ancestorInlines.some((ancestor) => ancestor.type === 'link');
- const sizes = await getImageSizes(size, src);
+ const sizes = await getImageSizes(context.contentContext, size, src);
return (
/* Ensure images dont expand to the size of the container where this Image may be nested in. Now it's always nested in a size-restricted container */
@@ -34,6 +36,7 @@ export async function InlineImage(props: InlineProps) {
) {
);
}
-async function getImageSizes(size: 'original' | 'line', src: ResolvedContentRef) {
+async function getImageSizes(
+ context: GitBookBaseContext | undefined,
+ size: 'original' | 'line',
+ src: ResolvedContentRef,
+) {
switch (size) {
case 'line': {
const imageSize =
src.file?.dimensions ??
- (await getImageSize(src.href, {
+ (await context?.imageResizer.getImageSize(src.href, {
dpr: 3,
}));
// We estimate that the maximum height of the line will be 40px
diff --git a/packages/gitbook/src/components/DocumentView/InlineLink.tsx b/packages/gitbook/src/components/DocumentView/InlineLink.tsx
index 6c644a9ee..0be0d4e0a 100644
--- a/packages/gitbook/src/components/DocumentView/InlineLink.tsx
+++ b/packages/gitbook/src/components/DocumentView/InlineLink.tsx
@@ -1,5 +1,7 @@
import { DocumentInlineLink, SiteInsightsLinkPosition } from '@gitbook/api';
+import { resolveContentRef } from '@/lib/references';
+
import { InlineProps } from './Inline';
import { Inlines } from './Inlines';
import { Link } from '../primitives';
@@ -7,7 +9,9 @@ import { Link } from '../primitives';
export async function InlineLink(props: InlineProps) {
const { inline, document, context, ancestorInlines } = props;
- const resolved = await context.resolveContentRef(inline.data.ref);
+ const resolved = context.contentContext
+ ? await resolveContentRef(inline.data.ref, context.contentContext)
+ : null;
if (!resolved) {
return (
diff --git a/packages/gitbook/src/components/DocumentView/Integration/IntegrationBlock.tsx b/packages/gitbook/src/components/DocumentView/Integration/IntegrationBlock.tsx
index 72ede9d59..e7ac937ed 100644
--- a/packages/gitbook/src/components/DocumentView/Integration/IntegrationBlock.tsx
+++ b/packages/gitbook/src/components/DocumentView/Integration/IntegrationBlock.tsx
@@ -41,13 +41,13 @@ const outputContext: ContentKitServerContext = {
export async function IntegrationBlock(props: BlockProps) {
const { block, context, style } = props;
- if (!context.content?.spaceId) {
+ if (!context.contentContext?.space) {
throw new Error('integration block requires a content.spaceId');
}
const contentKitContext: ContentKitContext = {
type: 'document',
- spaceId: context.content.spaceId,
+ spaceId: context.contentContext?.space.id,
editable: false,
theme: 'light', // TODO: how to handle this without moving rendering to the client side?
};
diff --git a/packages/gitbook/src/components/DocumentView/Mention.tsx b/packages/gitbook/src/components/DocumentView/Mention.tsx
index 27f6dcf1f..282954941 100644
--- a/packages/gitbook/src/components/DocumentView/Mention.tsx
+++ b/packages/gitbook/src/components/DocumentView/Mention.tsx
@@ -1,15 +1,18 @@
import { DocumentInlineMention, SiteInsightsLinkPosition } from '@gitbook/api';
import { StyledLink } from '@/components/primitives';
+import { resolveContentRef } from '@/lib/references';
import { InlineProps } from './Inline';
export async function Mention(props: InlineProps) {
const { inline, context } = props;
- const resolved = await context.resolveContentRef(inline.data.ref, {
- resolveAnchorText: true,
- });
+ const resolved = context.contentContext
+ ? await resolveContentRef(inline.data.ref, context.contentContext, {
+ resolveAnchorText: true,
+ })
+ : null;
if (!resolved) {
return null;
diff --git a/packages/gitbook/src/components/DocumentView/OpenAPI/OpenAPI.tsx b/packages/gitbook/src/components/DocumentView/OpenAPI/OpenAPI.tsx
index e56b41a24..f127ac20b 100644
--- a/packages/gitbook/src/components/DocumentView/OpenAPI/OpenAPI.tsx
+++ b/packages/gitbook/src/components/DocumentView/OpenAPI/OpenAPI.tsx
@@ -29,9 +29,13 @@ export async function OpenAPI(props: BlockProps) {
async function OpenAPIBody(props: BlockProps) {
const { block, context } = props;
+ if (!context.contentContext) {
+ return null;
+ }
+
const { data, specUrl, error } = await resolveOpenAPIBlock({
block,
- context: { resolveContentRef: context.resolveContentRef },
+ context: context.contentContext,
});
if (error) {
diff --git a/packages/gitbook/src/components/DocumentView/ReusableContent.tsx b/packages/gitbook/src/components/DocumentView/ReusableContent.tsx
index e8ed31312..fd234dd33 100644
--- a/packages/gitbook/src/components/DocumentView/ReusableContent.tsx
+++ b/packages/gitbook/src/components/DocumentView/ReusableContent.tsx
@@ -1,6 +1,6 @@
import { DocumentBlockReusableContent } from '@gitbook/api';
-import { getDocument } from '@/lib/api';
+import { resolveContentRef } from '@/lib/references';
import { BlockProps } from './Block';
import { UnwrappedBlocks } from './Blocks';
@@ -8,16 +8,19 @@ import { UnwrappedBlocks } from './Blocks';
export async function ReusableContent(props: BlockProps) {
const { block, context, ancestorBlocks } = props;
- if (!context.content) {
+ if (!context.contentContext) {
throw new Error(`Expected a content context to render a reusable content block`);
}
- const resolved = await context.resolveContentRef(block.data.ref);
+ const resolved = await resolveContentRef(block.data.ref, context.contentContext);
if (!resolved?.reusableContent?.document) {
return null;
}
- const document = await getDocument(context.content.spaceId, resolved.reusableContent.document);
+ const document = await context.contentContext.dataFetcher.getDocument({
+ spaceId: context.contentContext.space.id,
+ documentId: resolved.reusableContent.document,
+ });
if (!document) {
return null;
diff --git a/packages/gitbook/src/components/DocumentView/Table/RecordCard.tsx b/packages/gitbook/src/components/DocumentView/Table/RecordCard.tsx
index 3911d4811..ff7a6647e 100644
--- a/packages/gitbook/src/components/DocumentView/Table/RecordCard.tsx
+++ b/packages/gitbook/src/components/DocumentView/Table/RecordCard.tsx
@@ -3,6 +3,7 @@ import React from 'react';
import { Link } from '@/components/primitives';
import { Image } from '@/components/utils';
+import { resolveContentRef } from '@/lib/references';
import { ClassValue, tcls } from '@/lib/tailwind';
import { RecordColumnValue } from './RecordColumnValue';
@@ -19,14 +20,18 @@ export async function RecordCard(
const coverFile = view.coverDefinition
? getRecordValue(record[1], view.coverDefinition)?.[0]
: null;
- const cover = coverFile
- ? await context.resolveContentRef({ kind: 'file', file: coverFile })
- : null;
+ const cover =
+ coverFile && context.contentContext
+ ? await resolveContentRef({ kind: 'file', file: coverFile }, context.contentContext)
+ : null;
const targetRef = view.targetDefinition
? (record[1].values[view.targetDefinition] as ContentRef)
: null;
- const target = targetRef ? await context.resolveContentRef(targetRef) : null;
+ const target =
+ targetRef && context.contentContext
+ ? await resolveContentRef(targetRef, context.contentContext)
+ : null;
const coverIsSquareOrPortrait =
cover?.file?.dimensions &&
@@ -77,6 +82,7 @@ export async function RecordCard(
width: view.cardSize === 'medium' ? 245 : 376,
},
]}
+ resize={context.contentContext?.imageResizer}
className={tcls(
'min-w-0',
'w-full',
diff --git a/packages/gitbook/src/components/DocumentView/Table/RecordColumnValue.tsx b/packages/gitbook/src/components/DocumentView/Table/RecordColumnValue.tsx
index 8313429b9..95c454c21 100644
--- a/packages/gitbook/src/components/DocumentView/Table/RecordColumnValue.tsx
+++ b/packages/gitbook/src/components/DocumentView/Table/RecordColumnValue.tsx
@@ -12,6 +12,7 @@ import { StyledLink } from '@/components/primitives';
import { Image } from '@/components/utils';
import { getNodeFragmentByName } from '@/lib/document';
import { getSimplifiedContentType } from '@/lib/files';
+import { resolveContentRef } from '@/lib/references';
import { tcls } from '@/lib/tailwind';
import { filterOutNullable } from '@/lib/typescript';
@@ -141,10 +142,15 @@ export async function RecordColumnValue(
case 'files':
const files = await Promise.all(
(value as string[]).map((fileId) =>
- context.resolveContentRef({
- kind: 'file',
- file: fileId,
- }),
+ context.contentContext
+ ? resolveContentRef(
+ {
+ kind: 'file',
+ file: fileId,
+ },
+ context.contentContext,
+ )
+ : null,
),
);
@@ -181,6 +187,7 @@ export async function RecordColumnValue(
style={['max-h-[1lh]', 'h-[1lh]']}
alt={ref.text}
sizes={[{ width: 24 }]}
+ resize={context.contentContext?.imageResizer}
sources={{
light: {
src: ref.href,
@@ -206,12 +213,13 @@ export async function RecordColumnValue(
);
case 'content-ref': {
const contentRef = value ? (value as ContentRef) : null;
- const resolved = contentRef
- ? await context.resolveContentRef(contentRef, {
- resolveAnchorText: true,
- iconStyle: ['mr-2', 'text-tint-subtle'],
- })
- : null;
+ const resolved =
+ contentRef && context.contentContext
+ ? await resolveContentRef(contentRef, context.contentContext, {
+ resolveAnchorText: true,
+ iconStyle: ['mr-2', 'text-tint-subtle'],
+ })
+ : null;
return (
(
kind: 'user',
user: userId,
};
- const resolved = await context.resolveContentRef(contentRef);
+ const resolved = context.contentContext
+ ? await resolveContentRef(contentRef, context.contentContext)
+ : null;
if (!resolved) {
return null;
}
diff --git a/packages/gitbook/src/components/Footer/Footer.tsx b/packages/gitbook/src/components/Footer/Footer.tsx
index 973186d31..c2e706378 100644
--- a/packages/gitbook/src/components/Footer/Footer.tsx
+++ b/packages/gitbook/src/components/Footer/Footer.tsx
@@ -1,9 +1,8 @@
-import { CustomizationSettings, SiteCustomizationSettings, Space } from '@gitbook/api';
+import { GitBookSiteContext } from '@v2/lib/context';
import React from 'react';
import { Image } from '@/components/utils';
import { partition } from '@/lib/arrays';
-import { ContentRefContext } from '@/lib/references';
import { tcls } from '@/lib/tailwind';
import { FooterLinksGroup } from './FooterLinksGroup';
@@ -12,12 +11,9 @@ import { ThemeToggler } from '../ThemeToggler';
const FOOTER_COLUMNS = 4;
-export function Footer(props: {
- space: Space;
- context: ContentRefContext;
- customization: CustomizationSettings | SiteCustomizationSettings;
-}) {
- const { context, customization } = props;
+export function Footer(props: { context: GitBookSiteContext }) {
+ const { context } = props;
+ const { customization } = context;
return (
<>
@@ -58,6 +54,7 @@ export function Footer(props: {
{customization.footer.logo ? (
1;
+export function Header(props: { context: GitBookSiteContext; withTopHeader?: boolean }) {
+ const { context, withTopHeader } = props;
+ const { site, siteSpace, siteSpaces, sections, customization } = context;
+ const isMultiVariants = siteSpaces.length > 1;
return (
-
+
{isMultiVariants && (