Skip to content

Commit

Permalink
Cache URL derivation during generation
Browse files Browse the repository at this point in the history
Resolves #2386

Co-Authored-By: @ajesshope
  • Loading branch information
Gerrit0 committed Sep 4, 2023
1 parent 1f88a1f commit a6823cf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- TypeDoc will now attempt to cache icons when `DefaultThemeRenderContext.icons` is overwritten by a custom theme.
Note: To perform this optimization, TypeDoc relies on `DefaultThemeRenderContext.iconCache` being rendered within
each page. TypeDoc does it in the `defaultLayout` template.
- Cache URL derivation during generation, #2386.

### Bug Fixes

Expand All @@ -24,6 +25,7 @@

### Thanks!

- @ajesshope
- @HemalPatil
- @hrueger
- @typhonrt
Expand Down
10 changes: 9 additions & 1 deletion src/lib/output/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,12 @@ export abstract class ContextAwareRendererComponent extends RendererComponent {
this.listenTo(this.owner, {
[RendererEvent.BEGIN]: this.onBeginRenderer,
[PageEvent.BEGIN]: this.onBeginPage,
[RendererEvent.END]: () => this.absoluteToRelativePathMap.clear(),
});
}

private absoluteToRelativePathMap = new Map<string, string>();

/**
* Transform the given absolute path into a relative path.
*
Expand All @@ -59,7 +62,12 @@ export abstract class ContextAwareRendererComponent extends RendererComponent {
if (this.urlPrefix.test(absolute)) {
return absolute;
} else {
return Path.posix.relative(this.location, absolute) || ".";
const key = `${this.location}:${absolute}`;
let path = this.absoluteToRelativePathMap.get(key);
if (path) return path;
path = Path.posix.relative(this.location, absolute) || ".";
this.absoluteToRelativePathMap.set(key, path);
return path;
}
}

Expand Down

0 comments on commit a6823cf

Please sign in to comment.