@@ -53,6 +53,12 @@ export interface ResolveContentRefOptions {
53
53
* Styles to apply to the icon.
54
54
*/
55
55
iconStyle ?: ClassValue ;
56
+
57
+ /**
58
+ * Resolve the content URL as absolute.
59
+ * @default false
60
+ */
61
+ resolveAsAbsoluteURL ?: boolean ;
56
62
}
57
63
58
64
/**
@@ -63,7 +69,7 @@ export async function resolveContentRef(
63
69
context : GitBookAnyContext ,
64
70
options : ResolveContentRefOptions = { }
65
71
) : Promise < ResolvedContentRef | null > {
66
- const { resolveAnchorText = false , iconStyle } = options ;
72
+ const { resolveAnchorText = false , resolveAsAbsoluteURL = false , iconStyle } = options ;
67
73
const { linker, dataFetcher, space, revisionId, pages } = context ;
68
74
69
75
const activePage = 'page' in context ? context . page : undefined ;
@@ -144,8 +150,10 @@ export async function resolveContentRef(
144
150
icon = < PageIcon page = { page } style = { iconStyle } /> ;
145
151
}
146
152
153
+ const href = linker . toPathForPage ( { page, pages, anchor } ) ;
154
+
147
155
return {
148
- href : linker . toPathForPage ( { page , pages , anchor } ) ,
156
+ href : resolveAsAbsoluteURL ? linker . toAbsoluteURL ( href ) : href ,
149
157
text,
150
158
emoji,
151
159
icon,
@@ -311,11 +319,18 @@ async function resolveContentRefInSpace(
311
319
pathname : baseURL . pathname ,
312
320
} ) ;
313
321
314
- const resolved = await resolveContentRef ( contentRef , {
315
- ...spaceContext ,
316
- space,
317
- linker,
318
- } ) ;
322
+ const resolved = await resolveContentRef (
323
+ contentRef ,
324
+ {
325
+ ...spaceContext ,
326
+ space,
327
+ linker,
328
+ } ,
329
+ {
330
+ // Resolve pages as absolute URLs as we are in a different site.
331
+ resolveAsAbsoluteURL : true ,
332
+ }
333
+ ) ;
319
334
320
335
if ( ! resolved ) {
321
336
return null ;
0 commit comments