Skip to content

Commit

Permalink
Add navigation.compactFolders option
Browse files Browse the repository at this point in the history
Resolves #2667
  • Loading branch information
Gerrit0 committed Aug 18, 2024
1 parent 3673a4d commit 73e1dd6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Use of the `@extends` block tag no longer produces warnings, #2659.
This tag should only be used in JavaScript projects to specify the type parameters used when extending a parent class. It will not be rendered.
- Added new `navigation.compactFolders` option to prevent TypeDoc from compacting folders, similar to the VSCode option. #2667.

### Bug Fixes

Expand Down
28 changes: 15 additions & 13 deletions src/lib/output/themes/default/DefaultTheme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -445,19 +445,21 @@ export class DefaultTheme extends Theme {

// Now merge single-possible-paths together so we don't have folders in our navigation
// which contain only another single folder.
const queue = [...result];
while (queue.length) {
const review = queue.shift()!;
queue.push(...(review.children || []));
if (review.kind || review.path) continue;

if (review.children?.length === 1) {
const copyFrom = review.children[0];
const fullName = `${review.text}/${copyFrom.text}`;
delete review.children;
Object.assign(review, copyFrom);
review.text = fullName;
queue.push(review);
if (opts.compactFolders) {
const queue = [...result];
while (queue.length) {
const review = queue.shift()!;
queue.push(...(review.children || []));
if (review.kind || review.path) continue;

if (review.children?.length === 1) {
const copyFrom = review.children[0];
const fullName = `${review.text}/${copyFrom.text}`;
delete review.children;
Object.assign(review, copyFrom);
review.text = fullName;
queue.push(review);
}
}
}

Expand Down
1 change: 1 addition & 0 deletions src/lib/utils/options/declaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ export interface TypeDocOptionMap {
includeCategories: boolean;
includeGroups: boolean;
includeFolders: boolean;
compactFolders: boolean;
};
visibilityFilters: ManuallyValidatedOption<{
protected?: boolean;
Expand Down
1 change: 1 addition & 0 deletions src/lib/utils/options/sources/typedoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,7 @@ export function addTypeDocOptions(options: Pick<Options, "addDeclaration">) {
includeCategories: false,
includeGroups: false,
includeFolders: true,
compactFolders: true,
},
});

Expand Down

0 comments on commit 73e1dd6

Please sign in to comment.