@@ -41,8 +41,12 @@ export interface ResolvedContentRef {
4141 file ?: RevisionFile ;
4242 /** Page document resolved from the content ref */
4343 page ?: RevisionPageDocument ;
44- /** Resolved reusable content, if the ref points to reusable content on a revision. */
45- reusableContent ?: RevisionReusableContent ;
44+ /** Resolved reusable content, if the ref points to reusable content on a revision. Also contains the space and revision used for resolution. */
45+ reusableContent ?: {
46+ revisionReusableContent : RevisionReusableContent ;
47+ space : string ;
48+ revision : string ;
49+ } ;
4650 /** Resolve OpenAPI spec filesystem. */
4751 openAPIFilesystem ?: Filesystem ;
4852}
@@ -231,21 +235,52 @@ export async function resolveContentRef(
231235 }
232236
233237 case 'reusable-content' : {
238+ // Figure out which space and revision the reusable content is in.
239+ const container : { space : string ; revision : string } | null = await ( async ( ) => {
240+ // without a space on the content ref, or if the space is the same as the current one, we can use the current revision.
241+ if ( ! contentRef . space || contentRef . space === context . space . id ) {
242+ return { space : context . space . id , revision : revisionId } ;
243+ }
244+
245+ const space = await getDataOrNull (
246+ dataFetcher . getSpace ( {
247+ spaceId : contentRef . space ,
248+ shareKey : undefined ,
249+ } )
250+ ) ;
251+
252+ if ( ! space ) {
253+ return null ;
254+ }
255+
256+ return { space : space . id , revision : space . revision } ;
257+ } ) ( ) ;
258+
259+ if ( ! container ) {
260+ return null ;
261+ }
262+
234263 const reusableContent = await getDataOrNull (
235264 dataFetcher . getReusableContent ( {
236- spaceId : space . id ,
237- revisionId,
265+ spaceId : container . space ,
266+ revisionId : container . revision ,
238267 reusableContentId : contentRef . reusableContent ,
239268 } )
240269 ) ;
270+
241271 if ( ! reusableContent ) {
242272 return null ;
243273 }
274+
244275 return {
245- href : getGitBookAppHref ( `/s/${ space . id } ` ) ,
276+ href : getGitBookAppHref ( `/s/${ container . space } /~/reusable/ ${ reusableContent . id } ` ) ,
246277 text : reusableContent . title ,
247278 active : false ,
248- reusableContent,
279+ reusableContent : {
280+ revisionReusableContent : reusableContent ,
281+ space : container . space ,
282+ revision : container . revision ,
283+ } ,
249284 } ;
250285 }
251286
0 commit comments