mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-15 09:12:24 +02:00
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:
parent
721f14537d
commit
e4ecffe418
2 changed files with 46 additions and 3 deletions
|
@ -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', () => {
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue