Skip to content

Commit

Permalink
fix(docs): sidebar item label impact the pagination label of docs (#1…
Browse files Browse the repository at this point in the history
…0025)

Co-authored-by: sebastien <[email protected]>
  • Loading branch information
Abdullah-03 and slorber authored Apr 11, 2024
1 parent 721f145 commit e4ecffe
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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', () => {
Expand Down
15 changes: 12 additions & 3 deletions packages/docusaurus-plugin-content-docs/src/sidebars/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(
Expand Down Expand Up @@ -516,5 +523,7 @@ export function toNavigationLink(
permalink: navigationItem.link.permalink,
};
}
return toDocNavigationLink(getDocById(navigationItem.id));
return toDocNavigationLink(getDocById(navigationItem.id), {
sidebarItemLabel: navigationItem?.label,
});
}

0 comments on commit e4ecffe

Please sign in to comment.