diff --git a/src/app/[spaceId]/.gitbook/pdf/page.tsx b/src/app/[spaceId]/.gitbook/pdf/page.tsx index f9a5fbdcf..e730b3d95 100644 --- a/src/app/[spaceId]/.gitbook/pdf/page.tsx +++ b/src/app/[spaceId]/.gitbook/pdf/page.tsx @@ -27,10 +27,7 @@ export default async function PDFHTMLOutput(props: { const { params, searchParams } = props; const { spaceId } = params; - const [space, revision] = await Promise.all([ - getSpace(spaceId), - getCurrentRevision(spaceId), - ]); + const [space, revision] = await Promise.all([getSpace(spaceId), getCurrentRevision(spaceId)]); const pages = selectPages(revision, searchParams).slice(0, 4); // TODO: remove slice diff --git a/src/app/[spaceId]/fetch.ts b/src/app/[spaceId]/fetch.ts index ca2ab8621..665a0e4c1 100644 --- a/src/app/[spaceId]/fetch.ts +++ b/src/app/[spaceId]/fetch.ts @@ -20,10 +20,7 @@ export interface PageIdParams extends SpaceParams { export async function fetchPageData(params: PagePathParams | PageIdParams) { const { spaceId } = params; - const [space, revision] = await Promise.all([ - getSpace(spaceId), - getCurrentRevision(spaceId), - ]); + const [space, revision] = await Promise.all([getSpace(spaceId), getCurrentRevision(spaceId)]); const page = 'pageId' in params && params.pageId diff --git a/src/components/DocumentView/Block.tsx b/src/components/DocumentView/Block.tsx index 3d7488ec9..0e69272bb 100644 --- a/src/components/DocumentView/Block.tsx +++ b/src/components/DocumentView/Block.tsx @@ -16,6 +16,7 @@ import { Embed } from './Embed'; import { Quote } from './Quote'; import { DocumentBlockCode, + DocumentBlockContentRef, DocumentBlockDivider, DocumentBlockDrawing, DocumentBlockEmbed, @@ -43,6 +44,7 @@ import { ListTasks } from './ListTasks'; import { Divider } from './Divider'; import assertNever from 'assert-never'; import { Drawing } from './Drawing'; +import { BlockContentRef } from './BlockContentRef'; export type SupportedBlock = | DocumentBlockParagraph @@ -64,7 +66,8 @@ export type SupportedBlock = | DocumentBlockMath | DocumentBlockFile | DocumentBlockDivider - | DocumentBlockDrawing; + | DocumentBlockDrawing + | DocumentBlockContentRef; export type AncestorBlock = SupportedBlock | DocumentBlockTabsItem; @@ -118,6 +121,8 @@ export function Block(props: BlockProps) { return ; case 'drawing': return ; + case 'content-ref': + return ; default: assertNever(block); } diff --git a/src/components/DocumentView/BlockContentRef.tsx b/src/components/DocumentView/BlockContentRef.tsx new file mode 100644 index 000000000..c33c43c02 --- /dev/null +++ b/src/components/DocumentView/BlockContentRef.tsx @@ -0,0 +1,41 @@ +import { resolveContentRef } from '@/lib/references'; +import { DocumentBlockContentRef } from '@gitbook/api'; +import { BlockProps } from './Block'; +import { tcls } from '@/lib/tailwind'; +import IconFile from '@geist-ui/icons/file'; + +export async function BlockContentRef(props: BlockProps) { + const { block, context, style } = props; + + const resolved = await resolveContentRef(block.data.ref, context); + if (!resolved) { + return null; + } + + return ( + +
+ +
+
+
{resolved.text}
+
+
+ ); +} diff --git a/src/components/DocumentView/Inlines.tsx b/src/components/DocumentView/Inlines.tsx index 3d2e69134..69c22061c 100644 --- a/src/components/DocumentView/Inlines.tsx +++ b/src/components/DocumentView/Inlines.tsx @@ -3,7 +3,9 @@ import { Inline } from './Inline'; import { DocumentContextProps } from './DocumentView'; import { DocumentInlinesRich } from '@gitbook/api'; -export function Inlines(props: DocumentContextProps & { nodes: T[] }) { +export function Inlines( + props: DocumentContextProps & { nodes: T[] }, +) { const { nodes, ...contextProps } = props; return ( diff --git a/src/components/TableOfContents/PageLinkItem.tsx b/src/components/TableOfContents/PageLinkItem.tsx index f5076aa7b..791e26734 100644 --- a/src/components/TableOfContents/PageLinkItem.tsx +++ b/src/components/TableOfContents/PageLinkItem.tsx @@ -2,29 +2,32 @@ import { RevisionPageLink } from '@gitbook/api'; import { tcls } from '@/lib/tailwind'; import Link from 'next/link'; -export function PageLinkItem(props: { - page: RevisionPageLink; -}) { +export function PageLinkItem(props: { page: RevisionPageLink }) { const { page } = props; return (
  • - {page.title} + + {page.title} +
  • ); } diff --git a/src/components/TableOfContents/PagesList.tsx b/src/components/TableOfContents/PagesList.tsx index 4bdd7a1c1..e0b19f962 100644 --- a/src/components/TableOfContents/PagesList.tsx +++ b/src/components/TableOfContents/PagesList.tsx @@ -25,12 +25,7 @@ export function PagesList(props: { /> ); } else if (page.type === 'link') { - return ( - - ); + return ; } return ( diff --git a/src/lib/api.ts b/src/lib/api.ts index 0685eb7f5..f9a79c93f 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -22,32 +22,42 @@ export function api(): GitBookAPI { /** * Get a space by its ID. */ -export const getSpace = unstable_cache(async (spaceId: string) => { - const { data } = await api().spaces.getSpaceById(spaceId); - return data; -}, ['api', 'spaces'], { - tags: ['api', 'spaces'] -}); +export const getSpace = unstable_cache( + async (spaceId: string) => { + const { data } = await api().spaces.getSpaceById(spaceId); + return data; + }, + ['api', 'spaces'], + { + tags: ['api', 'spaces'], + }, +); /** * Get the current revision of a space */ -export const getCurrentRevision = unstable_cache(async (spaceId: string) => { - const { data } = await api().spaces.getCurrentRevision(spaceId); - return data; -}, ['api', 'revisions'], { - tags: ['api', 'revisions'] -}); +export const getCurrentRevision = unstable_cache( + async (spaceId: string) => { + const { data } = await api().spaces.getCurrentRevision(spaceId); + return data; + }, + ['api', 'revisions'], + { + tags: ['api', 'revisions'], + }, +); /** * Get the document for a page. */ -export const getPageDocument = unstable_cache(async (spaceId: string, revisionId: string, pageId: string) => { - const { data } = await api().spaces.getPageInRevisionById(spaceId, revisionId, pageId); - // @ts-ignore - return data.document as JSONDocument; -}, ['api', 'documents'], { - tags: ['api', 'documents'] -}); - - +export const getPageDocument = unstable_cache( + async (spaceId: string, revisionId: string, pageId: string) => { + const { data } = await api().spaces.getPageInRevisionById(spaceId, revisionId, pageId); + // @ts-ignore + return data.document as JSONDocument; + }, + ['api', 'documents'], + { + tags: ['api', 'documents'], + }, +);