Skip to content

Commit

Permalink
feat(docusaurus): strikeout deprecated items in sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
tgreyuk committed Dec 30, 2024
1 parent 0abd3bc commit 1f781d5
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 4 deletions.
1 change: 0 additions & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"updateInternalDependencies": "minor",
"ignore": [
"@devtools/*",
"docusaurus-plugin-typedoc",
"typedoc-github-wiki-theme",
"typedoc-gitlab-wiki-theme",
"typedoc-vitepress-theme",
Expand Down
5 changes: 5 additions & 0 deletions .changeset/eleven-bags-doubt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'docusaurus-plugin-typedoc': minor
---

- Strikeout deprecated items in sidebar (#747).
17 changes: 15 additions & 2 deletions packages/docusaurus-plugin-typedoc/src/utils/get-sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function getNavigationItem(
if (navigationItem.children?.length) {
return {
type: 'category',
label: `${navigationItem.title}`,
label: getNavigationLabel(navigationItem),
items: getSidebar(navigationItem.children, basePath, numberPrefixParser),
...(id && {
link: {
Expand All @@ -57,7 +57,20 @@ function getNavigationItem(
? {
type: 'doc',
id,
label: `${navigationItem.title}`,
label: getNavigationLabel(navigationItem),
}
: null;
}

function getNavigationLabel(navigationItem: NavigationItem) {
return navigationItem.isDeprecated
? strikethrough(navigationItem.title)
: navigationItem.title;
}

function strikethrough(label: string) {
return label
.split('')
.map((char) => char + '\u0336')
.join('');
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ title: "test"
exports[`Docusaurus: Defaults should render sidebar 1`] = `
"// @ts-check
/** @type {import('@docusaurus/plugin-content-docs').SidebarsConfig} */
const typedocSidebar = { items: [{"type":"category","label":"links","items":[{"type":"category","label":"Enumerations","items":[{"type":"doc","id":"out/default/links/enumerations/CommentEnum","label":"CommentEnum"}]},{"type":"category","label":"Interfaces","items":[{"type":"doc","id":"out/default/links/interfaces/CommentInterface","label":"CommentInterface"},{"type":"doc","id":"out/default/links/interfaces/CommentInterfaceExtended","label":"CommentInterfaceExtended"}]}],"link":{"type":"doc","id":"out/default/links/index"}},{"type":"category","label":"module-1","items":[{"type":"category","label":"CategoryA","items":[{"type":"doc","id":"out/default/module-1/classes/ClassA","label":"ClassA"}]},{"type":"category","label":"CategoryB","items":[{"type":"doc","id":"out/default/module-1/classes/ClassB","label":"ClassB"},{"type":"doc","id":"out/default/module-1/interfaces/InterfaceA","label":"InterfaceA"},{"type":"doc","id":"out/default/module-1/interfaces/InterfaceB","label":"InterfaceB"}]}],"link":{"type":"doc","id":"out/default/module-1/index"}},{"type":"category","label":"module-2","items":[{"type":"category","label":"Classes","items":[{"type":"doc","id":"out/default/module-2/classes/ClassA","label":"ClassA"},{"type":"doc","id":"out/default/module-2/classes/ClassB","label":"ClassB"}]},{"type":"category","label":"Interfaces","items":[{"type":"doc","id":"out/default/module-2/interfaces/InterfaceA","label":"InterfaceA"},{"type":"doc","id":"out/default/module-2/interfaces/InterfaceB","label":"InterfaceB"}]}],"link":{"type":"doc","id":"out/default/module-2/index"}}]};
const typedocSidebar = { items: [{"type":"category","label":"links","items":[{"type":"category","label":"Enumerations","items":[{"type":"doc","id":"out/default/links/enumerations/CommentEnum","label":"CommentEnum"}]},{"type":"category","label":"Interfaces","items":[{"type":"doc","id":"out/default/links/interfaces/CommentInterface","label":"CommentInterface"},{"type":"doc","id":"out/default/links/interfaces/CommentInterfaceExtended","label":"CommentInterfaceExtended"}]}],"link":{"type":"doc","id":"out/default/links/index"}},{"type":"category","label":"module-1","items":[{"type":"category","label":"CategoryA","items":[{"type":"doc","id":"out/default/module-1/classes/ClassA","label":"ClassA"}]},{"type":"category","label":"CategoryB","items":[{"type":"doc","id":"out/default/module-1/classes/ClassB","label":"ClassB"},{"type":"doc","id":"out/default/module-1/classes/ClassC","label":"ClassC"},{"type":"doc","id":"out/default/module-1/interfaces/InterfaceA","label":"InterfaceA"},{"type":"doc","id":"out/default/module-1/interfaces/InterfaceB","label":"InterfaceB"}]}],"link":{"type":"doc","id":"out/default/module-1/index"}},{"type":"category","label":"module-2","items":[{"type":"category","label":"Classes","items":[{"type":"doc","id":"out/default/module-2/classes/ClassA","label":"ClassA"},{"type":"doc","id":"out/default/module-2/classes/ClassB","label":"ClassB"}]},{"type":"category","label":"Interfaces","items":[{"type":"doc","id":"out/default/module-2/interfaces/ClassC","label":"C̶l̶a̶s̶s̶C̶"},{"type":"doc","id":"out/default/module-2/interfaces/InterfaceA","label":"InterfaceA"},{"type":"doc","id":"out/default/module-2/interfaces/InterfaceB","label":"InterfaceB"}]}],"link":{"type":"doc","id":"out/default/module-2/index"}}]};
module.exports = typedocSidebar.items;"
`;

Expand All @@ -32,6 +32,7 @@ exports[`Docusaurus: Global Members should render docs 1`] = `
## CategoryB
- [ClassB](classes/ClassB.mdx)
- [~~ClassC~~](classes/ClassC.mdx)
- [InterfaceA](interfaces/InterfaceA.mdx)
- [InterfaceB](interfaces/InterfaceB.mdx)
"
Expand Down Expand Up @@ -148,6 +149,11 @@ const typedocSidebar = { items: [
"id": "out/global-members/classes/ClassB",
"label": "ClassB"
},
{
"type": "doc",
"id": "out/global-members/classes/ClassC",
"label": "ClassC"
},
{
"type": "doc",
"id": "out/global-members/interfaces/InterfaceA",
Expand Down
7 changes: 7 additions & 0 deletions packages/docusaurus-plugin-typedoc/test/stubs/src/module-1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ export class ClassA {}
* @category CategoryB
*/
export class ClassB {}
/**
*
* @category CategoryB
*
* @deprecated Deprecated symbol
*/
export class ClassC {}
/**
* @category CategoryB
*/
Expand Down
6 changes: 6 additions & 0 deletions packages/docusaurus-plugin-typedoc/test/stubs/src/module-2.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
export class ClassA {}
export class ClassB {}
/**
* @deprecated
*
* Deprecated symbol
*/
export interface ClassC {}

export interface InterfaceA {}
export interface InterfaceB {}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ export interface InterfaceA {
export interface InterfaceB {}
export enum EnumA {}
export enum EnumB {}

/**
* @deprecated
*/
export class ClassA {}
/**
* @deprecated
*/
export class ClassB {}
export type TypeA = string;
export type TypeB = string;

0 comments on commit 1f781d5

Please sign in to comment.