-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(docusaurus): correctly handle sidebar ids with custom docs paths (#…
…648)
- Loading branch information
Showing
4 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'docusaurus-plugin-typedoc': patch | ||
--- | ||
|
||
- Correctly handle sidebar ids with custom docs paths (#648) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
packages/docusaurus-plugin-typedoc/src/utils/adjust-basedir.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { adjustBaseDirectory } from './adjust-basedir'; | ||
|
||
describe('adjustPath', () => { | ||
it('should handle paths', () => { | ||
const originalPath = 'folder/api-reference'; | ||
const subPath = 'folder'; | ||
const expected = 'api-reference'; | ||
expect(adjustBaseDirectory(originalPath, subPath)).toBe(expected); | ||
}); | ||
|
||
it('should handle relative paths', () => { | ||
const originalPath = 'docs/api-reference'; | ||
const subPath = '../docs'; | ||
const expected = 'api-reference'; | ||
expect(adjustBaseDirectory(originalPath, subPath)).toBe(expected); | ||
}); | ||
}); |
36 changes: 36 additions & 0 deletions
36
packages/docusaurus-plugin-typedoc/src/utils/adjust-basedir.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import * as path from 'path'; | ||
|
||
/** | ||
* This method is designed to resolve the base directory paths for documentation presets. | ||
*/ | ||
export function adjustBaseDirectory(originalPath: string, subPath: string) { | ||
// Normalize the paths to handle different path formats and OS differences | ||
originalPath = path.normalize(originalPath); | ||
subPath = path.normalize(subPath); | ||
|
||
// Split the original path into an array of segments | ||
const segments = originalPath.split(path.sep); | ||
|
||
// Split the sub path into an array of segments and filter out ".." to handle relative paths | ||
const subSegments = subPath | ||
.split(path.sep) | ||
.filter((segment) => segment !== '..'); | ||
|
||
// Find the index of the first sub path segment in the original path segments | ||
const startIndex = segments.indexOf(subSegments[0]); | ||
|
||
// Remove the sub path segments from the original path segments if found | ||
if (startIndex !== -1) { | ||
segments.splice(startIndex, subSegments.length); | ||
} | ||
|
||
// Join the segments back into a path and remove the leading slash if present | ||
let newPath = segments.join(path.sep); | ||
|
||
// Ensure there is no leading slash | ||
if (newPath.startsWith(path.sep)) { | ||
newPath = newPath.slice(1); | ||
} | ||
|
||
return newPath; | ||
} |