Compare commits

...

1 Commits

Author SHA1 Message Date
Nicolas Dorseuil 03be3e79de Add isSpaceInSiteStructure function and update resolveContentRef logic for cross-space references 2026-03-13 13:35:01 +01:00
2 changed files with 22 additions and 1 deletions
+14 -1
View File
@@ -29,7 +29,12 @@ import { PageIcon } from '@/components/PageIcon';
import { getGitBookAppHref } from './app';
import { getBlockById, getBlockTitle } from './document';
import { resolvePageId } from './pages';
import { findSiteSpaceBy, getFallbackSiteSpacePath, getLocalizedTitle } from './sites';
import {
findSiteSpaceBy,
getFallbackSiteSpacePath,
getLocalizedTitle,
isSpaceInSiteStructure,
} from './sites';
import { getRevisionTags, resolveTag } from './tags';
import type { ClassValue } from './tailwind';
import { filterOutNullable } from './typescript';
@@ -163,6 +168,14 @@ export async function resolveContentRef(
case 'anchor':
case 'page': {
if (isContentRefInDifferentSpace(contentRef, context)) {
// Only resolve cross-space page/anchor refs when the target space
// is part of the current site's structure.
if (
'site' in context &&
!isSpaceInSiteStructure(context.structure, contentRef.space)
) {
return null;
}
return resolveContentRefInSpace(contentRef.space, context, contentRef, options);
}
+8
View File
@@ -57,6 +57,14 @@ export function listAllSiteSpaces(siteStructure: SiteStructure) {
});
}
/**
* Check if a space is part of a site structure by scanning every site section
* and all the siteSpaces associated with each section.
*/
export function isSpaceInSiteStructure(siteStructure: SiteStructure, spaceId: string): boolean {
return !!findSiteSpaceBy(siteStructure, (siteSpace) => siteSpace.space.id === spaceId);
}
/**
* Find a site space by its spaceId in a site structure.
*/