Skip to content

Commit 7902e33

Browse files
committed
Updated url resolving logic to match default theme
1 parent a858837 commit 7902e33

File tree

1 file changed

+59
-53
lines changed

1 file changed

+59
-53
lines changed

src/theme/index.ts

Lines changed: 59 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ export class MarkdownTheme extends DefaultTheme {
2323
const mapping = DefaultTheme.getMapping(reflection);
2424

2525
if (mapping) {
26-
const url = [mapping.directory, MarkdownTheme.getUrl(reflection) + '.md'].join('/');
27-
urls.push(new UrlMapping(url, reflection, mapping.template));
28-
reflection.url = url;
29-
reflection.hasOwnDocument = true;
26+
if (!reflection.url || !DefaultTheme.URL_PREFIX.test(reflection.url)) {
27+
const url = [mapping.directory, DefaultTheme.getUrl(reflection) + '.md'].join('/');
28+
urls.push(new UrlMapping(url, reflection, mapping.template));
29+
reflection.url = url;
30+
reflection.hasOwnDocument = true;
31+
}
3032
for (const key in reflection.children) {
3133
if (reflection.children.hasOwnProperty(key)) {
3234
const child = reflection.children[key];
@@ -55,55 +57,59 @@ export class MarkdownTheme extends DefaultTheme {
5557

5658
const options = ThemeService.getOptions();
5759

58-
let anchor = DefaultTheme.getUrl(reflection, container, '.');
59-
/* tslint:disable */
60-
if (reflection['isStatic']) {
61-
anchor = 'static-' + anchor;
62-
}
63-
/* tslint:enable */
64-
65-
let anchorRef = '';
66-
67-
switch (reflection.kind) {
68-
case ReflectionKind.ExternalModule:
69-
anchorRef = `external-module-${ThemeService.getAnchorRef(reflection.name)}-`;
70-
break;
71-
case ReflectionKind.Class:
72-
anchorRef = `class-${ThemeService.getAnchorRef(reflection.name)}`;
73-
break;
74-
case ReflectionKind.Interface:
75-
anchorRef = `interface-${ThemeService.getAnchorRef(reflection.name)}`;
76-
break;
77-
case ReflectionKind.Module:
78-
anchorRef = `module-${ThemeService.getAnchorRef(reflection.name)}`;
79-
case ReflectionKind.Enum:
80-
if (reflection.parent.kind === 0 || reflection.parent.kind === ReflectionKind.ExternalModule) {
60+
if (!reflection.url || !DefaultTheme.URL_PREFIX.test(reflection.url)) {
61+
62+
let anchor = DefaultTheme.getUrl(reflection, container, '.');
63+
/* tslint:disable */
64+
if (reflection['isStatic']) {
65+
anchor = 'static-' + anchor;
66+
}
67+
/* tslint:enable */
68+
69+
let anchorRef = '';
70+
71+
switch (reflection.kind) {
72+
case ReflectionKind.ExternalModule:
73+
anchorRef = `external-module-${ThemeService.getAnchorRef(reflection.name)}-`;
74+
break;
75+
case ReflectionKind.Class:
76+
anchorRef = `class-${ThemeService.getAnchorRef(reflection.name)}`;
77+
break;
78+
case ReflectionKind.Interface:
79+
anchorRef = `interface-${ThemeService.getAnchorRef(reflection.name)}`;
80+
break;
81+
case ReflectionKind.Module:
8182
anchorRef = `module-${ThemeService.getAnchorRef(reflection.name)}`;
82-
} else {
83-
anchorRef = `enumeration-${ThemeService.getAnchorRef(reflection.name)}`;
84-
}
85-
break;
86-
default:
87-
if (options.mdFlavour === 'bitbucket') {
88-
let anchorPrefix = '';
89-
if (reflection.kind === ReflectionKind.ObjectLiteral) {
90-
anchorPrefix += 'object-literal-';
83+
case ReflectionKind.Enum:
84+
if (reflection.parent.kind === 0 || reflection.parent.kind === ReflectionKind.ExternalModule) {
85+
anchorRef = `module-${ThemeService.getAnchorRef(reflection.name)}`;
86+
} else {
87+
anchorRef = `enumeration-${ThemeService.getAnchorRef(reflection.name)}`;
88+
}
89+
break;
90+
default:
91+
if (options.mdFlavour === 'bitbucket') {
92+
let anchorPrefix = '';
93+
if (reflection.kind === ReflectionKind.ObjectLiteral) {
94+
anchorPrefix += 'object-literal-';
95+
}
96+
reflection.flags.forEach((flag) => {
97+
anchorPrefix += `${flag}-`;
98+
});
99+
const prefixRef = ThemeService.getAnchorRef(anchorPrefix);
100+
const reflectionRef = ThemeService.getAnchorRef(reflection.name);
101+
anchorRef = `markdown-header-${prefixRef}${reflectionRef}`;
102+
} else {
103+
anchorRef = anchor;
91104
}
92-
reflection.flags.forEach((flag) => {
93-
anchorPrefix += `${flag}-`;
94-
});
95-
const prefixRef = ThemeService.getAnchorRef(anchorPrefix);
96-
const reflectionRef = ThemeService.getAnchorRef(reflection.name);
97-
anchorRef = `markdown-header-${prefixRef}${reflectionRef}`;
98-
} else {
99-
anchorRef = anchor;
100-
}
101105

102-
}
106+
}
103107

104-
reflection.url = (container.url !== undefined ? container.url : '') + '#' + anchorRef;
105-
reflection.anchor = anchor;
106-
reflection.hasOwnDocument = false;
108+
reflection.url = (container.url !== undefined ? container.url : '') + '#' + anchorRef;
109+
reflection.anchor = anchor;
110+
reflection.hasOwnDocument = false;
111+
112+
}
107113

108114
reflection.traverse((child: any) => {
109115
if (child instanceof DeclarationReflection) {
@@ -166,10 +172,10 @@ export class MarkdownTheme extends DefaultTheme {
166172
urls.push(new UrlMapping('README.md', context, 'reflection.hbs'));
167173

168174
if (entryPoint.children) {
169-
entryPoint.children.forEach((child: DeclarationReflection) => {
170-
MarkdownTheme.buildUrls(child, urls);
171-
});
172-
}
175+
entryPoint.children.forEach((child: DeclarationReflection) => {
176+
MarkdownTheme.buildUrls(child, urls);
177+
});
178+
}
173179

174180
return urls;
175181
}

0 commit comments

Comments
 (0)