mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-21 01:53:26 +00:00
Remove deprecated synced block from GitBook Open (#2546)
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'gitbook': minor
|
||||
---
|
||||
|
||||
Remove deprecated synced block from GitBook Open
|
||||
@@ -16,7 +16,7 @@
|
||||
"clean": "rm -rf ./.next && rm -rf ./public/~gitbook/static"
|
||||
},
|
||||
"dependencies": {
|
||||
"@gitbook/api": "^0.72.0",
|
||||
"@gitbook/api": "^0.73.0",
|
||||
"@gitbook/cache-do": "workspace:*",
|
||||
"@gitbook/emoji-codepoints": "workspace:*",
|
||||
"@gitbook/icons": "workspace:*",
|
||||
|
||||
@@ -11,7 +11,6 @@ import {
|
||||
import { ClassValue } from '@/lib/tailwind';
|
||||
|
||||
import { BlockContentRef } from './BlockContentRef';
|
||||
import { BlockSyncedBlock } from './BlockSyncedBlock';
|
||||
import { CodeBlock } from './CodeBlock';
|
||||
import { Divider } from './Divider';
|
||||
import { DocumentContextProps } from './DocumentView';
|
||||
@@ -107,8 +106,6 @@ export function Block<T extends DocumentBlock>(props: BlockProps<T>) {
|
||||
throw new Error('Blocks should be directly rendered by parent');
|
||||
case 'integration':
|
||||
return <IntegrationBlock {...props} block={block} />;
|
||||
case 'synced-block':
|
||||
return <BlockSyncedBlock {...props} block={block} />;
|
||||
case 'reusable-content':
|
||||
return <ReusableContent {...props} block={block} />;
|
||||
case 'stepper':
|
||||
@@ -165,7 +162,6 @@ export function BlockSkeleton(props: { block: DocumentBlock; style: ClassValue }
|
||||
case 'content-ref':
|
||||
case 'integration':
|
||||
case 'stepper':
|
||||
case 'synced-block':
|
||||
case 'reusable-content':
|
||||
return <SkeletonCard id={id} style={style} />;
|
||||
case 'embed':
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
import { DocumentBlockSyncedBlock } from '@gitbook/api';
|
||||
|
||||
import { getSyncedBlockContent } from '@/lib/api';
|
||||
import { resolveContentRefWithFiles } from '@/lib/references';
|
||||
|
||||
import { BlockProps } from './Block';
|
||||
import { Blocks, UnwrappedBlocks } from './Blocks';
|
||||
|
||||
export async function BlockSyncedBlock(props: BlockProps<DocumentBlockSyncedBlock>) {
|
||||
const { block, ancestorBlocks, context, style } = props;
|
||||
|
||||
const apiToken = block.meta?.apiToken;
|
||||
if (!apiToken) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// We can't resolve the synced block without an organization context.
|
||||
if (!context.contentRefContext) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const syncedBlock = await getSyncedBlockContent(
|
||||
apiToken,
|
||||
context.contentRefContext.space.organization,
|
||||
block.data.ref.syncedBlock,
|
||||
);
|
||||
|
||||
if (!syncedBlock) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<UnwrappedBlocks
|
||||
nodes={syncedBlock.document.nodes}
|
||||
document={syncedBlock.document}
|
||||
ancestorBlocks={[...ancestorBlocks, block]}
|
||||
context={{
|
||||
...context,
|
||||
resolveContentRef: async (ref, options) => {
|
||||
if (!syncedBlock?.files) {
|
||||
return context.resolveContentRef(ref, options);
|
||||
}
|
||||
const result = resolveContentRefWithFiles(syncedBlock.files, ref);
|
||||
if (result !== undefined) {
|
||||
return result;
|
||||
}
|
||||
return context.resolveContentRef(ref, options);
|
||||
},
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -192,48 +192,6 @@ export const getUserById = cache({
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* Get a synced block by its ref.
|
||||
*/
|
||||
export const getSyncedBlockContent = cache({
|
||||
name: 'api.getSyncedBlockContent',
|
||||
tag: (apiToken, organizationId, syncedBlockId) =>
|
||||
getAPICacheTag({
|
||||
tag: 'synced-block',
|
||||
syncedBlock: syncedBlockId,
|
||||
}),
|
||||
get: async (
|
||||
apiToken: string,
|
||||
organizationId: string,
|
||||
syncedBlockId: string,
|
||||
options: CacheFunctionOptions,
|
||||
) => {
|
||||
try {
|
||||
const response = await apiWithToken(apiToken).orgs.getSyncedBlockContent(
|
||||
organizationId,
|
||||
syncedBlockId,
|
||||
{
|
||||
...noCacheFetchOptions,
|
||||
signal: options.signal,
|
||||
},
|
||||
);
|
||||
return cacheResponse(response, {
|
||||
revalidateBefore: 60 * 60,
|
||||
});
|
||||
} catch (error) {
|
||||
if ((error as GitBookAPIError).code === 404) {
|
||||
return {
|
||||
revalidateBefore: 60 * 60,
|
||||
data: null,
|
||||
};
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
// We don't cache apiToken as it's not a stable key
|
||||
getKeyArgs: (args) => [args[1], args[2]],
|
||||
});
|
||||
/**
|
||||
* Resolve a URL to the content to render.
|
||||
*/
|
||||
@@ -1208,11 +1166,6 @@ export function getAPICacheTag(
|
||||
tag: 'collection';
|
||||
collection: string;
|
||||
}
|
||||
// All data related to a synced block
|
||||
| {
|
||||
tag: 'synced-block';
|
||||
syncedBlock: string;
|
||||
}
|
||||
// All data related to a site
|
||||
| {
|
||||
tag: 'site';
|
||||
@@ -1234,8 +1187,6 @@ export function getAPICacheTag(
|
||||
return `space:${spec.space}:document:${spec.document}`;
|
||||
case 'collection':
|
||||
return `collection:${spec.collection}`;
|
||||
case 'synced-block':
|
||||
return `synced-block:${spec.syncedBlock}`;
|
||||
case 'site':
|
||||
return `site:${spec.site}`;
|
||||
case 'integration':
|
||||
|
||||
@@ -281,8 +281,6 @@ export async function resolveContentRef(
|
||||
reusableContent,
|
||||
};
|
||||
}
|
||||
case 'synced-block':
|
||||
return null;
|
||||
|
||||
default:
|
||||
assertNever(contentRef);
|
||||
@@ -328,22 +326,3 @@ async function resolveContentRefInSpace(
|
||||
subText: space.title,
|
||||
};
|
||||
}
|
||||
|
||||
export function resolveContentRefWithFiles(
|
||||
files: RevisionFile[],
|
||||
contentRef: ContentRef,
|
||||
): ResolvedContentRef | null | undefined {
|
||||
if (contentRef.kind === 'file') {
|
||||
const file = files.find((file) => file.id === contentRef.file);
|
||||
if (file) {
|
||||
return {
|
||||
href: file.downloadURL,
|
||||
text: file.name,
|
||||
active: false,
|
||||
file,
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user