Skip to content

Commit 4113ce1

Browse files
committed
Move logging for bad URLs to router
Also fix an issue which was resulting in `#undefined` links
1 parent 03072c3 commit 4113ce1

File tree

4 files changed

+13
-18
lines changed

4 files changed

+13
-18
lines changed

src/lib/output/router.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,11 @@ export abstract class BaseRouter implements Router {
180180
}
181181

182182
getAnchor(refl: Reflection): string | undefined {
183+
if (!this.anchors.has(refl)) {
184+
this.application.logger.verbose(
185+
`${refl.getFullName()} does not have an anchor but one was requested, this is a bug in the theme`,
186+
);
187+
}
183188
return this.anchors.get(refl);
184189
}
185190

@@ -209,6 +214,9 @@ export abstract class BaseRouter implements Router {
209214
}
210215

211216
if (equal && !to.isProject()) {
217+
if (fromUrl === toUrl) {
218+
return "";
219+
}
212220
return `#${this.getAnchor(to)}`;
213221
}
214222

src/lib/output/themes/MarkedPlugin.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ export class MarkedPlugin extends ContextAwareRendererComponent {
153153
// If we don't have a URL the user probably linked to some deeply nested property
154154
// which doesn't get an assigned URL. We'll walk upwards until we find a reflection
155155
// which has a URL and link to that instead.
156-
if (!url) {
156+
if (typeof url === "undefined") {
157157
// Walk upwards to find something we can link to.
158158
let target = part.target.parent!;
159159
while (!context.router.hasUrl(target)) {

src/lib/output/themes/default/DefaultThemeRenderContext.ts

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import { reflectionTemplate } from "./templates/reflection.js";
3737
import { typeDeclaration, typeDetails, typeDetailsIfUseful } from "./partials/typeDetails.js";
3838
import { moduleMemberSummary, moduleReflection } from "./partials/moduleReflection.js";
3939
import type { Router } from "../../router.js";
40-
import type { NeverIfInternal, TranslatedString } from "#utils";
40+
import type { NeverIfInternal } from "#utils";
4141

4242
function bind<F, L extends any[], R>(fn: (f: F, ...a: L) => R, first: F) {
4343
return (...r: L) => fn(first, ...r);
@@ -88,25 +88,11 @@ export class DefaultThemeRenderContext {
8888
};
8989

9090
getAnchor = (reflection: Reflection): string | undefined => {
91-
const anchor = this.router.getAnchor(reflection);
92-
if (!anchor) {
93-
// This will go to debug level before release
94-
this.theme.application.logger.warn(
95-
`${reflection.getFullName()} does not have an anchor but one was requested when generating page for ${this.model.getFullName()}, this is a bug` as TranslatedString,
96-
);
97-
}
98-
return anchor;
91+
return this.router.getAnchor(reflection);
9992
};
10093

10194
urlTo = (reflection: Reflection): string | undefined => {
102-
if (this.router.hasUrl(reflection)) {
103-
return this.router.relativeUrl(this.page.model, reflection);
104-
}
105-
// This will go to debug level before release
106-
this.theme.application.logger.warn(
107-
`${reflection.getFullName()} does not have a URL but was linked to when generating page for ${this.model.getFullName()}, this is a bug` as TranslatedString,
108-
);
109-
return undefined;
95+
return this.router.relativeUrl(this.page.model, reflection);
11096
};
11197

11298
markdown = (

src/test/output/router.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ describe("KindRouter", () => {
131131
equal(router.relativeUrl(Obj, ObjArray), "ObjArray.html");
132132
equal(router.relativeUrl(Foo, codeGen), "#codegeneration");
133133
equal(router.relativeUrl(iterator, codeGen), "#codegeneration");
134+
equal(router.relativeUrl(Foo, Foo), "");
134135
});
135136

136137
it("Can get a URL to an asset relative to the base", () => {

0 commit comments

Comments
 (0)