fix(docs): sidebar item label impact the pagination label of docs (#10025)

Co-authored-by: sebastien <lorber.sebastien@gmail.com>
This commit is contained in:
Abdullah Saud 2024-04-11 21:26:11 +05:00 committed by GitHub
parent 721f14537d
commit e4ecffe418
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 46 additions and 3 deletions

View file

@ -719,6 +719,22 @@ describe('toDocNavigationLink', () => {
} as PropNavigationLink);
});
it('with sidebar item label', () => {
expect(
toDocNavigationLink(
testDoc({
title: 'Doc Title',
permalink: '/docPermalink',
frontMatter: {},
}),
{sidebarItemLabel: 'Doc sidebar item label'},
),
).toEqual({
title: 'Doc sidebar item label',
permalink: '/docPermalink',
} as PropNavigationLink);
});
it('with pagination_label + sidebar_label front matter', () => {
expect(
toDocNavigationLink(
@ -736,6 +752,24 @@ describe('toDocNavigationLink', () => {
permalink: '/docPermalink',
} as PropNavigationLink);
});
it('with sidebar_label + sidebar item label', () => {
expect(
toDocNavigationLink(
testDoc({
title: 'Doc Title',
permalink: '/docPermalink',
frontMatter: {
sidebar_label: 'sidebar_label',
},
}),
{sidebarItemLabel: 'Doc sidebar item label'},
),
).toEqual({
title: 'sidebar_label',
permalink: '/docPermalink',
} as PropNavigationLink);
});
});
describe('toNavigationLink', () => {

View file

@ -478,7 +478,10 @@ Available document ids are:
};
}
export function toDocNavigationLink(doc: DocMetadataBase): PropNavigationLink {
export function toDocNavigationLink(
doc: DocMetadataBase,
options?: {sidebarItemLabel?: string | undefined},
): PropNavigationLink {
const {
title,
permalink,
@ -487,7 +490,11 @@ export function toDocNavigationLink(doc: DocMetadataBase): PropNavigationLink {
sidebar_label: sidebarLabel,
},
} = doc;
return {title: paginationLabel ?? sidebarLabel ?? title, permalink};
return {
title:
paginationLabel ?? sidebarLabel ?? options?.sidebarItemLabel ?? title,
permalink,
};
}
export function toNavigationLink(
@ -516,5 +523,7 @@ export function toNavigationLink(
permalink: navigationItem.link.permalink,
};
}
return toDocNavigationLink(getDocById(navigationItem.id));
return toDocNavigationLink(getDocById(navigationItem.id), {
sidebarItemLabel: navigationItem?.label,
});
}