Skip to content

Commit 9c7856d

Browse files
committed
docs: display package name in sidebar
1 parent e8f5a30 commit 9c7856d

3 files changed

Lines changed: 26 additions & 14 deletions

File tree

β€Ždocs/.vitepress/config/en.tsβ€Ž

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,16 @@ const guideSidebar = [
5959
},
6060
{
6161
text: "API Reference",
62-
items: PACKAGES.map((pkg) => ({
63-
text: pkg,
62+
items: Object.entries(PACKAGES).map(([pkg, name]) => ({
63+
text: name,
6464
link: `/reference/api/${pkg}/`,
6565
})),
6666
},
6767
];
6868

6969
const sidebar = {
7070
...Object.fromEntries(
71-
PACKAGES.map((pkg) => [
71+
Object.keys(PACKAGES).map((pkg) => [
7272
`/reference/api/${pkg}/`,
7373
[
7474
{

β€Ždocs/.vitepress/config/zh.tsβ€Ž

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,16 @@ const guideSidebar = [
5959
},
6060
{
6161
text: "API 参考",
62-
items: PACKAGES.map((pkg) => ({
63-
text: pkg,
62+
items: Object.entries(PACKAGES).map(([pkg, name]) => ({
63+
text: name,
6464
link: `/zh/reference/api/${pkg}/`,
6565
})),
6666
},
6767
];
6868

6969
const sidebar = {
7070
...Object.fromEntries(
71-
PACKAGES.map((pkg) => [
71+
Object.keys(PACKAGES).map((pkg) => [
7272
`/zh/reference/api/${pkg}/`,
7373
[
7474
{

β€Ždocs/.vitepress/scripts/generate-reference.tsβ€Ž

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
1-
import { existsSync, readdirSync } from "node:fs";
1+
import { existsSync, readFileSync, readdirSync } from "node:fs";
22
import { cp, rename, rm } from "node:fs/promises";
33

44
import type { TypeDocOptions } from "typedoc";
55
import { Application } from "typedoc";
66

77
const LANGUAGES = ["zh"];
88
const IGNORED_PACKAGES = ["test-utils"];
9-
export const PACKAGES = readdirSync("../packages", { withFileTypes: true })
10-
.filter((dirent) => dirent.isDirectory())
11-
.map((dirent) => dirent.name)
12-
.filter((name) => !IGNORED_PACKAGES.includes(name));
9+
export const PACKAGES = Object.fromEntries(
10+
readdirSync("../packages", { withFileTypes: true })
11+
.filter((dirent) => dirent.isDirectory())
12+
.map((dirent) => dirent.name)
13+
.filter((name) => !IGNORED_PACKAGES.includes(name))
14+
.map((name) => {
15+
const pkgPath = `../packages/${name}/package.json`;
16+
if (!existsSync(pkgPath)) {
17+
throw new Error(`Package.json not found for package: ${name}`);
18+
}
19+
const pkgJson = JSON.parse(readFileSync(pkgPath, "utf-8"));
20+
21+
return [name, pkgJson.name as string] as const;
22+
})
23+
.sort(([a], [b]) => a.localeCompare(b)),
24+
);
1325
const tsconfig = "../tsconfig.json";
1426

1527
if (import.meta.main) {
@@ -19,14 +31,14 @@ if (import.meta.main) {
1931
await rm("reference/api", { recursive: true, force: true });
2032

2133
// Generate API documentation
22-
for (const pkg of PACKAGES) {
23-
console.log(`πŸ“š Generating reference for ${pkg}...`);
34+
for (const [pkg, name] of Object.entries(PACKAGES)) {
35+
console.log(`πŸ“š Generating reference for ${name}...`);
2436
await runTypedoc(tsconfig, pkg);
2537
}
2638
console.log("βœ… Reference generated successfully!");
2739
console.log("πŸ“š Beautifying reference structure...");
2840

29-
for (const pkg of PACKAGES) {
41+
for (const pkg of Object.keys(PACKAGES)) {
3042
if (existsSync(`reference/api/${pkg}/globals.md`)) {
3143
await rm(`reference/api/${pkg}/index.md`, { force: true });
3244
await rename(

0 commit comments

Comments
Β (0)