Skip to content

Commit e6b2ae1

Browse files
authored
docs: make api reference landing prettier (#1727)
* feat(client-documentation-generator): skip too long navigation * docs: update typedoc plugins dependencies * docs(core-packages-documentation-generator): update landing page navigation
1 parent 6437e24 commit e6b2ae1

File tree

7 files changed

+88
-49
lines changed

7 files changed

+88
-49
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,4 @@
115115
],
116116
"**/*.{ts,js,md,json}": "prettier --write"
117117
}
118-
}
118+
}

packages/client-documentation-generator/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"@types/jest": "^26.0.4",
2828
"@types/node": "^10.0.0",
2929
"jest": "^26.1.0",
30-
"typedoc": "^0.17.8",
30+
"typedoc": "^0.19.2",
3131
"typescript": "~4.0.2"
3232
},
3333
"homepage": "https://github.com/aws/aws-sdk-js-v3/tree/master/packages/client-documentation-generator",

packages/client-documentation-generator/src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { PluginHost } from "typedoc/dist/lib/utils";
22

33
import { SdkClientCommentUpdatePlugin } from "./sdk-client-comment-update";
4+
import { SdkClientRemoveNavigatorPlugin } from "./sdk-client-remove-navigator";
45
import { SdkClientRenameProjectPlugin } from "./sdk-client-rename-project";
56
import { SdkClientTocPlugin } from "./sdk-client-toc-plugin";
67

@@ -17,4 +18,8 @@ module.exports = function load(pluginHost: PluginHost) {
1718
"SdkClientRenameProjectPlugin",
1819
new SdkClientRenameProjectPlugin(application.renderer)
1920
);
21+
application.renderer.addComponent(
22+
"SdkClientRemoveNavigatorPlugin",
23+
new SdkClientRemoveNavigatorPlugin(application.renderer)
24+
);
2025
};
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { Component, RendererComponent } from "typedoc/dist/lib/output/components";
2+
import { RendererEvent } from "typedoc/dist/lib/output/events";
3+
import { NavigationPlugin } from "typedoc/dist/lib/output/plugins";
4+
5+
@Component({ name: "SdkClientRemoveNavigator" })
6+
export class SdkClientRemoveNavigatorPlugin extends RendererComponent {
7+
private navigationPlugin: NavigationPlugin;
8+
9+
initialize() {
10+
this.navigationPlugin = <any>this.owner.application.renderer.getComponent("navigation");
11+
this.listenTo(this.owner, {
12+
[RendererEvent.BEGIN]: this.onRenderedBegin,
13+
});
14+
}
15+
16+
onRenderedBegin(event: RendererEvent) {
17+
const navigationItem = this.navigationPlugin.navigation;
18+
if (!navigationItem) {
19+
return;
20+
}
21+
navigationItem.children = [];
22+
}
23+
}

packages/core-packages-documentation-generator/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"@types/jest": "^26.0.4",
2828
"@types/node": "^10.0.0",
2929
"jest": "^26.1.0",
30-
"typedoc": "^0.17.8",
30+
"typedoc": "^0.19.2",
3131
"typescript": "~4.0.2"
3232
},
3333
"private": true,

packages/core-packages-documentation-generator/src/sdk-index-link-client.ts

Lines changed: 56 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { isAbsolute, join, relative, resolve, sep } from "path";
22
import { BindOption } from "typedoc";
33
import { Component, RendererComponent } from "typedoc/dist/lib/output/components";
44
import { PageEvent } from "typedoc/dist/lib/output/events";
5+
import { NavigationItem } from "typedoc/dist/lib/output/models/NavigationItem";
56

67
const PROJECT_ROOT = join(__dirname, "..", "..", "..", "..");
78
@Component({ name: "SdkIndexLinkClientPlugin" })
@@ -25,26 +26,69 @@ export class SdkIndexLinkClientPlugin extends RendererComponent {
2526
onPageBegin(page: PageEvent) {
2627
const out = isAbsolute(this.out) ? this.out : resolve(PROJECT_ROOT, this.out);
2728
const clientDocs = isAbsolute(this.clientDocs) ? this.clientDocs : resolve(PROJECT_ROOT, this.clientDocs);
28-
2929
// Get relative path from core packages doc to clients' doc.
3030
const clientDocsPattern = relative(out, clientDocs);
31+
3132
if (page.model === page.project) {
32-
// Entry point index.html and global.html page.
33-
page.project.children
34-
.filter((child) => child.sources[0].fileName.startsWith(`clients${sep}`))
35-
.forEach((child) => {
36-
// "clients/client-s3" => "client-s3"
37-
const clientName = child.sources[0].fileName.split(sep)[1];
38-
const clientDocDir = clientDocsPattern.replace(/{{CLIENT}}/g, clientName);
39-
child.url = join(clientDocDir, "index.html");
40-
// @ts-ignore attach temporary flag.
41-
child._skipRendering = true;
42-
});
33+
page.navigation = this.groupNavigation(page.navigation);
34+
35+
page.navigation.children.filter(this.isClient).forEach((child) => {
36+
// "clients/client-s3" => "client-s3"
37+
const clientName = child.reflection.sources[0].fileName.split(sep)[1];
38+
const clientDocDir = clientDocsPattern.replace(/{{CLIENT}}/g, clientName);
39+
child.url = join(clientDocDir, "index.html");
40+
// @ts-ignore attach temporary flag.
41+
child.reflection._skipRendering = true;
42+
});
4343
}
4444

4545
// Skip rendering empty landing page for each client.
4646
if (page.model._skipRendering) {
4747
page.preventDefault();
4848
}
4949
}
50+
51+
/**
52+
* Group navigation in Client, Packages and Libraries sections. It will update the
53+
* supplied navigation object;
54+
*/
55+
private groupNavigation(navigation: NavigationItem): NavigationItem {
56+
if (this.isGrouped(navigation)) return navigation;
57+
58+
const modules = navigation.children.filter((child) => child?.reflection?.sources[0].fileName);
59+
const clients: NavigationItem[] = [];
60+
const packages: NavigationItem[] = [];
61+
const libs: NavigationItem[] = [];
62+
const isLib = (item: NavigationItem) => item?.reflection?.sources[0].fileName.startsWith(`lib${sep}`);
63+
modules.forEach((item) => {
64+
if (this.isClient(item)) {
65+
clients.push(item);
66+
} else if (isLib(item)) {
67+
libs.push(item);
68+
} else {
69+
packages.push(item);
70+
}
71+
});
72+
73+
navigation.children = [
74+
new NavigationItem("Clients"),
75+
...clients,
76+
new NavigationItem("Libraries"),
77+
...libs,
78+
new NavigationItem("Packages"),
79+
...packages,
80+
];
81+
return navigation;
82+
}
83+
84+
private isGrouped(navigation: NavigationItem): boolean {
85+
const childrenNames = navigation.children.map((child) => child.title);
86+
return (
87+
childrenNames.includes("Clients") && childrenNames.includes("Packages") && childrenNames.includes("Libraries")
88+
);
89+
}
90+
91+
private isClient(item: NavigationItem): boolean {
92+
return item?.reflection?.sources[0].fileName.startsWith(`clients${sep}`);
93+
}
5094
}

yarn.lock

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5630,11 +5630,6 @@ [email protected]:
56305630
resolved "https://registry.yarnpkg.com/he/-/he-1.2.0.tgz#84ae65fa7eafb165fddb61566ae14baf05664f0f"
56315631
integrity sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==
56325632

5633-
highlight.js@^10.0.0:
5634-
version "10.3.1"
5635-
resolved "https://registry.yarnpkg.com/highlight.js/-/highlight.js-10.3.1.tgz#3ca6bf007377faae347e8135ff25900aac734b9a"
5636-
integrity sha512-jeW8rdPdhshYKObedYg5XGbpVgb1/DT4AHvDFXhkU7UnGSIjy9kkJ7zHG7qplhFHMitTSzh5/iClKQk3Kb2RFQ==
5637-
56385633
highlight.js@^10.2.0:
56395634
version "10.4.0"
56405635
resolved "https://registry.yarnpkg.com/highlight.js/-/highlight.js-10.4.0.tgz#ef3ce475e5dfa7a48484260b49ea242ddab823a0"
@@ -7624,7 +7619,7 @@ [email protected]:
76247619
dependencies:
76257620
lunr ">= 2.3.0 < 2.4.0"
76267621

7627-
"lunr@>= 2.3.0 < 2.4.0", lunr@^2.3.8:
7622+
"lunr@>= 2.3.0 < 2.4.0":
76287623
version "2.3.8"
76297624
resolved "https://registry.yarnpkg.com/lunr/-/lunr-2.3.8.tgz#a8b89c31f30b5a044b97d2d28e2da191b6ba2072"
76307625
integrity sha512-oxMeX/Y35PNFuZoHp+jUj5OSEmLCaIH4KTFJh7a93cHBoFmpw2IoPs22VIz7vyO2YUnx2Tn9dzIwO2P/4quIRg==
@@ -7717,11 +7712,6 @@ map-visit@^1.0.0:
77177712
dependencies:
77187713
object-visit "^1.0.0"
77197714

7720-
7721-
version "1.0.0"
7722-
resolved "https://registry.yarnpkg.com/marked/-/marked-1.0.0.tgz#d35784245a04871e5988a491e28867362e941693"
7723-
integrity sha512-Wo+L1pWTVibfrSr+TTtMuiMfNzmZWiOPeO7rZsQUY5bgsxpHesBEcIWJloWVTFnrMXnf/TL30eTFSGJddmQAng==
7724-
77257715
77267716
version "1.1.1"
77277717
resolved "https://registry.yarnpkg.com/marked/-/marked-1.1.1.tgz#e5d61b69842210d5df57b05856e0c91572703e6a"
@@ -11061,13 +11051,6 @@ typedarray@^0.0.6:
1106111051
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
1106211052
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=
1106311053

11064-
typedoc-default-themes@^0.10.2:
11065-
version "0.10.2"
11066-
resolved "https://registry.yarnpkg.com/typedoc-default-themes/-/typedoc-default-themes-0.10.2.tgz#743380a80afe62c5ef92ca1bd4abe2ac596be4d2"
11067-
integrity sha512-zo09yRj+xwLFE3hyhJeVHWRSPuKEIAsFK5r2u47KL/HBKqpwdUSanoaz5L34IKiSATFrjG5ywmIu98hPVMfxZg==
11068-
dependencies:
11069-
lunr "^2.3.8"
11070-
1107111054
typedoc-default-themes@^0.11.4:
1107211055
version "0.11.4"
1107311056
resolved "https://registry.yarnpkg.com/typedoc-default-themes/-/typedoc-default-themes-0.11.4.tgz#1bc55b7c8d1132844616ff6f570e1e2cd0eb7343"
@@ -11078,22 +11061,6 @@ typedoc-plugin-lerna-packages@^0.3.1:
1107811061
resolved "https://registry.yarnpkg.com/typedoc-plugin-lerna-packages/-/typedoc-plugin-lerna-packages-0.3.1.tgz#3e65068e6c6ef987fc4c4553416af3fb22c8a5e6"
1107911062
integrity sha512-azeP5DVv4Me+C32RoGbMAzXo7JeYmeEstMAx4mdtVGHLtrXjitlaf0pS562vogofwyIcyVnjL6BlZWvbPQ3hmw==
1108011063

11081-
typedoc@^0.17.8:
11082-
version "0.17.8"
11083-
resolved "https://registry.yarnpkg.com/typedoc/-/typedoc-0.17.8.tgz#96b67e9454aa7853bfc4dc9a55c8a07adfd5478e"
11084-
integrity sha512-/OyrHCJ8jtzu+QZ+771YaxQ9s4g5Z3XsQE3Ma7q+BL392xxBn4UMvvCdVnqKC2T/dz03/VXSLVKOP3lHmDdc/w==
11085-
dependencies:
11086-
fs-extra "^8.1.0"
11087-
handlebars "^4.7.6"
11088-
highlight.js "^10.0.0"
11089-
lodash "^4.17.15"
11090-
lunr "^2.3.8"
11091-
marked "1.0.0"
11092-
minimatch "^3.0.0"
11093-
progress "^2.0.3"
11094-
shelljs "^0.8.4"
11095-
typedoc-default-themes "^0.10.2"
11096-
1109711064
typedoc@^0.19.2:
1109811065
version "0.19.2"
1109911066
resolved "https://registry.yarnpkg.com/typedoc/-/typedoc-0.19.2.tgz#842a63a581f4920f76b0346bb80eb2a49afc2c28"

0 commit comments

Comments
 (0)