Skip to content

Commit 146855f

Browse files
committed
fix(core): correctly handle package index paths
1 parent 24c1dea commit 146855f

File tree

26 files changed

+22
-125
lines changed

26 files changed

+22
-125
lines changed

.changeset/forty-onions-relate.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'typedoc-plugin-markdown': patch
3+
---
4+
5+
- Correctly handle package index paths (#782).
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
import * as path from 'path';
2+
13
export function replaceFilename(originalPath: string, newFileName: string) {
2-
return originalPath.replace(/\/[^/]+(\.[^/.]+)$/, `/${newFileName}$1`);
4+
const normalizedPath = originalPath.replace(/\\/g, '/');
5+
const updatedPath = normalizedPath.replace(
6+
/\/[^/]+(\.[^/.]+)$/,
7+
`${path.sep}${newFileName}$1`,
8+
);
9+
return path.sep === '\\' ? updatedPath.replace(/\//g, '\\') : updatedPath;
310
}

packages/typedoc-plugin-markdown/src/theme/context/partials/page.packagesIndex.ts

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,12 @@ export function packagesIndex(
6060

6161
function getPackageLink(
6262
context: MarkdownThemeContext,
63-
reflection: DeclarationReflection,
63+
projectPackage: DeclarationReflection,
6464
) {
65-
const packageEntryModule = context.router.getPackageEntryModule(reflection);
66-
67-
if (packageEntryModule) {
68-
return context.urlTo(packageEntryModule);
69-
}
70-
71-
if (reflection.readme?.length && !context.options.getValue('mergeReadme')) {
72-
return replaceFilename(
73-
context.urlTo(reflection),
74-
context.router.getModulesFileName(reflection),
75-
);
76-
}
77-
78-
return replaceFilename(
79-
context.urlTo(reflection),
80-
context.router.getPackageEntryFileName(reflection) || '',
81-
);
65+
return projectPackage.readme
66+
? replaceFilename(
67+
context.urlTo(projectPackage),
68+
context.router.getPackageEntryFileName(projectPackage) || '',
69+
)
70+
: context.urlTo(projectPackage);
8271
}

packages/typedoc-plugin-markdown/test/fixtures/src/packages-categories/package-1/index.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

packages/typedoc-plugin-markdown/test/fixtures/src/packages-categories/package-1/package.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

packages/typedoc-plugin-markdown/test/fixtures/src/packages-categories/package-1/tsconfig.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

packages/typedoc-plugin-markdown/test/fixtures/src/packages-categories/package-1/typedoc.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

packages/typedoc-plugin-markdown/test/fixtures/src/packages-categories/package-2/README.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

packages/typedoc-plugin-markdown/test/fixtures/src/packages-categories/package-2/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/typedoc-plugin-markdown/test/fixtures/src/packages-categories/package-2/package.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)