@@ -41,8 +41,12 @@ export interface ResolvedContentRef {
41
41
file ?: RevisionFile ;
42
42
/** Page document resolved from the content ref */
43
43
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
+ } ;
46
50
/** Resolve OpenAPI spec filesystem. */
47
51
openAPIFilesystem ?: Filesystem ;
48
52
}
@@ -231,21 +235,52 @@ export async function resolveContentRef(
231
235
}
232
236
233
237
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
+
234
263
const reusableContent = await getDataOrNull (
235
264
dataFetcher . getReusableContent ( {
236
- spaceId : space . id ,
237
- revisionId,
265
+ spaceId : container . space ,
266
+ revisionId : container . revision ,
238
267
reusableContentId : contentRef . reusableContent ,
239
268
} )
240
269
) ;
270
+
241
271
if ( ! reusableContent ) {
242
272
return null ;
243
273
}
274
+
244
275
return {
245
- href : getGitBookAppHref ( `/s/${ space . id } ` ) ,
276
+ href : getGitBookAppHref ( `/s/${ container . space } /~/reusable/ ${ reusableContent . id } ` ) ,
246
277
text : reusableContent . title ,
247
278
active : false ,
248
- reusableContent,
279
+ reusableContent : {
280
+ revisionReusableContent : reusableContent ,
281
+ space : container . space ,
282
+ revision : container . revision ,
283
+ } ,
249
284
} ;
250
285
}
251
286
0 commit comments