@@ -36,8 +36,25 @@ Future<shelf.Response> documentationHandler(shelf.Request request) async {
36
36
if (docFilePath.version == null ) {
37
37
return redirectResponse (pkgDocUrl (docFilePath.package, isLatest: true ));
38
38
}
39
- if (docFilePath.path == null ) {
40
- return redirectResponse ('${request .requestedUri }/' );
39
+ final detectedPath = docFilePath.path;
40
+ if (detectedPath == null ) {
41
+ return redirectResponse (
42
+ pkgDocUrl (docFilePath.package, version: docFilePath.version));
43
+ }
44
+ // 8.3.0 dartdoc links to directories without an ending slash.
45
+ // This breaks base-uri, sidebar does not load, links do not work.
46
+ // Redirecting to the proper directory ending with slash.
47
+ if (detectedPath.split ('/' ).last == 'index.html' &&
48
+ ! request.requestedUri.path.endsWith ('/' ) &&
49
+ ! request.requestedUri.path.endsWith ('/index.html' )) {
50
+ // removes last segment `index.html` and adds `/` at the end of the url.
51
+ return redirectResponse (
52
+ pkgDocUrl (
53
+ docFilePath.package,
54
+ version: docFilePath.version,
55
+ relativePath: detectedPath,
56
+ ),
57
+ );
41
58
}
42
59
final String requestMethod = request.method.toUpperCase ();
43
60
@@ -59,10 +76,10 @@ Future<shelf.Response> documentationHandler(shelf.Request request) async {
59
76
return redirectResponse (pkgDocUrl (
60
77
package,
61
78
version: resolved.urlSegment,
62
- relativePath: docFilePath.path ,
79
+ relativePath: detectedPath ,
63
80
));
64
81
} else {
65
- return await handleDartDoc (request, package, resolved, docFilePath.path ! );
82
+ return await handleDartDoc (request, package, resolved, detectedPath );
66
83
}
67
84
}
68
85
0 commit comments