Resolve repository page URLs without an opt-in flag

This commit is contained in:
taranvohra
2026-09-18 12:22:53 +05:30
parent 3c177f04a2
commit 59bc231ccd
8 changed files with 16 additions and 30 deletions
@@ -18,7 +18,6 @@ export async function BlockContentRef(props: BlockProps<DocumentBlockContentRef>
const resolved = context.contentContext
? await resolveContentRefInDocument(document, block.data.ref, context.contentContext, {
resolveGitPageURLs: true,
resolveAnchorText: true,
iconStyle: ['text-xl', 'text-tint'],
})
@@ -76,9 +76,7 @@ export async function InlineLinkButton(
const resolved =
context.contentContext && inline.data.ref
? await resolveContentRefInDocument(document, inline.data.ref, context.contentContext, {
resolveGitPageURLs: true,
})
? await resolveContentRefInDocument(document, inline.data.ref, context.contentContext)
: null;
const href =
@@ -19,7 +19,6 @@ export async function InlineLink(props: InlineProps<DocumentInlineLink>) {
const resolved = context.contentContext
? await resolveContentRefInDocument(document, inline.data.ref, context.contentContext, {
resolveGitPageURLs: true,
// We don't want to resolve the anchor text here, as it can be very expensive and will block rendering if there is a lot of anchors link.
resolveAnchorText: false,
})
@@ -9,7 +9,6 @@ export async function Mention(props: InlineProps<DocumentInlineMention>) {
const resolved = context.contentContext
? await resolveContentRefInDocument(document, inline.data.ref, context.contentContext, {
resolveGitPageURLs: true,
resolveAnchorText: true,
})
: null;
@@ -41,9 +41,7 @@ export async function RecordCard(
? resolveContentRefInDocument(document, dark.contentRef, context.contentContext)
: null,
targetRef && context.contentContext
? resolveContentRefInDocument(document, targetRef, context.contentContext, {
resolveGitPageURLs: true,
})
? resolveContentRefInDocument(document, targetRef, context.contentContext)
: null,
]);
@@ -253,7 +253,6 @@ export async function RecordColumnValue<Tag extends React.ElementType = 'div'>(
const resolved =
value && context.contentContext
? await resolveContentRefInDocument(document, value, context.contentContext, {
resolveGitPageURLs: true,
resolveAnchorText: true,
iconStyle: ['mr-2', 'text-tint-subtle'],
})
+13 -17
View File
@@ -807,11 +807,10 @@ describe('repository page links', () => {
kind: 'url' as const,
url: 'https://github.com/acme/docs/tree/main/api/auth.md#tokens',
};
const options = { resolveGitPageURLs: true };
it('renders a matching repository URL as a site page link with its anchor', async () => {
const { context, getRevision } = fixture();
const result = await resolveContentRef(ref, context, options);
const result = await resolveContentRef(ref, context);
expect(result?.href).toBe('/api/authentication#tokens');
expect(result?.text).toBe('Authentication');
expect(result?.ancestors?.[0]?.label).toBe('API');
@@ -829,10 +828,13 @@ describe('repository page links', () => {
expect(ref.kind).toBe('url');
});
it('keeps media/resource URL resolution unchanged unless enabled', async () => {
const { context, getSpace } = fixture();
expect((await resolveContentRef(ref, context))?.href).toBe(ref.url);
expect(getSpace).not.toHaveBeenCalled();
it('preserves asset URLs that do not match a page', async () => {
const { context } = fixture();
const assetRef = {
kind: 'url' as const,
url: ref.url.replace('auth.md#tokens', 'diagram.png'),
};
expect((await resolveContentRef(assetRef, context))?.href).toBe(assetRef.url);
});
it('reads only the matching space in a 500-space site', async () => {
@@ -855,9 +857,7 @@ describe('repository page links', () => {
},
}))
);
expect((await resolveContentRef(ref, context, options))?.href).toBe(
'/api/authentication#tokens'
);
expect((await resolveContentRef(ref, context))?.href).toBe('/api/authentication#tokens');
expect(getSpace).toHaveBeenCalledTimes(1);
expect(getRevision).toHaveBeenCalledTimes(1);
});
@@ -866,7 +866,7 @@ describe('repository page links', () => {
'preserves the fallback for unavailable content: %j',
async (state) => {
const { context } = fixture(state);
const result = await resolveContentRef(ref, context, options);
const result = await resolveContentRef(ref, context);
expect(result).toEqual({ href: ref.url, text: ref.url, active: false });
}
);
@@ -877,9 +877,7 @@ describe('repository page links', () => {
ref.url.replace('/main/', '/preview/'),
ref.url.replace('/acme/', '/other/'),
]) {
expect((await resolveContentRef({ kind: 'url', url }, context, options))?.href).toBe(
url
);
expect((await resolveContentRef({ kind: 'url', url }, context))?.href).toBe(url);
}
expect(getRevision).not.toHaveBeenCalled();
});
@@ -887,10 +885,8 @@ describe('repository page links', () => {
it('resolves the unchanged stored URL when the target becomes available', async () => {
const state = { missing: true };
const { context } = fixture(state);
expect((await resolveContentRef(ref, context, options))?.href).toBe(ref.url);
expect((await resolveContentRef(ref, context))?.href).toBe(ref.url);
state.missing = false;
expect((await resolveContentRef(ref, context, options))?.href).toBe(
'/api/authentication#tokens'
);
expect((await resolveContentRef(ref, context))?.href).toBe('/api/authentication#tokens');
});
});
+1 -3
View File
@@ -84,8 +84,6 @@ export interface ResolvedContentRef {
}
export interface ResolveContentRefOptions {
/** Enable repository-page lookup for navigational links. */
resolveGitPageURLs?: boolean;
/**
* Should the content ref be rendered as text.
* @default false
@@ -149,7 +147,7 @@ export async function resolveContentRef(
switch (contentRef.kind) {
case 'url': {
if (options.resolveGitPageURLs && 'site' in context) {
if ('site' in context) {
const target = findGitPageURLTarget(
contentRef.url,
listAllSiteSpaces(context.structure)