Skip to content

Commit abbd891

Browse files
committed
fix a bug in extractModulePath for versioned docs
1 parent c7bb65c commit abbd891

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

docs/dokka-presets/scripts/custom-navigation-loader.js

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,23 @@
55
* https://sdk.amazonaws.com/kotlin/api/latest/index.html -> index.html
66
* https://sdk.amazonaws.com/kotlin/api/latest/s3/index.html -> s3
77
* https://sdk.amazonaws.com/kotlin/api/latest/s3/aws.sdk.kotlin.services.s3/index.html -> s3
8+
* https://sdk.amazonaws.com/kotlin/api/1.4.109/s3/index.html -> s3
89
*/
910
function extractModulePath(href) {
1011
try {
11-
const url = new URL(href, window.location.origin);
12-
const pathSegments = url.pathname.split('/').filter(Boolean);
13-
14-
var moduleIndex = -1;
15-
16-
for (let i = 1; i < pathSegments.length; i++) {
17-
if (pathSegments[i].includes('.')) {
18-
moduleIndex = i-1;
19-
break;
20-
}
21-
}
22-
23-
if (moduleIndex === -1) {
24-
return "index.html";
25-
} else {
26-
return pathSegments.slice(0, moduleIndex + 1).join("/");
27-
}
28-
} catch (error) {
12+
const segments = new URL(href, window.location.origin)
13+
.pathname
14+
.split('/') // break the path
15+
.filter(Boolean); // drop empty parts
16+
17+
// the URL pattern is always ".../kotlin/api/<version>/..."
18+
const apiPos = segments.indexOf('api');
19+
if (apiPos === -1) return null;
20+
21+
// segment after "api" is the version ("latest", "1.4.109", etc.)
22+
// segment after _that_ is the module name (or "index.html" if we're at the root)
23+
return segments[apiPos + 2] ?? 'index.html';
24+
} catch {
2925
return null;
3026
}
3127
}

0 commit comments

Comments
 (0)