Skip to content

Commit 152eea6

Browse files
authored
docs: fix autogeneration of the appkit-ui API reference sidebar (#80)
1 parent 3886c8e commit 152eea6

5 files changed

Lines changed: 58 additions & 26 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"label": "Data components",
3+
"position": 3
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"label": "UI components",
3+
"position": 2
4+
}

docs/docusaurus.config.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,25 @@ const config: Config = {
8585
...args
8686
}) {
8787
const sidebarItems = await defaultSidebarItemsGenerator(args);
88-
// exclude API reference - this category is handled manually in sidebars.ts
89-
return sidebarItems.filter(
90-
(item) =>
91-
item.type !== "category" ||
92-
item.link?.type !== "doc" ||
93-
item.link.id !== "api/index",
94-
);
88+
89+
return sidebarItems.filter((item) => {
90+
// Exclude API reference category - handled manually in sidebars.ts
91+
if (
92+
item.type === "category" &&
93+
item.link?.type === "doc" &&
94+
item.link.id === "api/index"
95+
) {
96+
return false;
97+
}
98+
99+
// Exclude api/appkit-ui/index - automatically used as category link in sidebars.ts
100+
// Explicit dirName in sidebars.ts bypasses automatic exclusion
101+
if (item.type === "doc" && item.id === "api/appkit-ui/index") {
102+
return false;
103+
}
104+
105+
return true;
106+
});
95107
},
96108
},
97109
theme: {

docs/sidebars.ts

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -83,24 +83,8 @@ const sidebars: SidebarsConfig = {
8383
},
8484
items: [
8585
{
86-
type: "category",
87-
label: "UI components",
88-
items: [
89-
{
90-
type: "autogenerated",
91-
dirName: "api/appkit-ui/ui",
92-
},
93-
],
94-
},
95-
{
96-
type: "category",
97-
label: "Data components",
98-
items: [
99-
{
100-
type: "autogenerated",
101-
dirName: "api/appkit-ui/data",
102-
},
103-
],
86+
type: "autogenerated",
87+
dirName: "api/appkit-ui",
10488
},
10589
],
10690
},

tools/generate-component-mdx.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const FILE_EXTENSIONS = {
2323
EXAMPLE: ".example.tsx",
2424
TEST_PATTERN: ".test.",
2525
INDEX: "/index.tsx",
26+
CATEGORY_CONFIG: "_category_.json",
2627
} as const;
2728

2829
const COMPONENT_PATTERNS = {
@@ -557,7 +558,8 @@ function main() {
557558
// Create output directory if it doesn't exist
558559
fs.mkdirSync(outputDir, { recursive: true });
559560

560-
// Delete only subdirectories (preserve files like index.md)
561+
// Delete only subdirectories (preserve root-level files)
562+
// This preserves files like _index.md (category link) and styling.md (manual docs)
561563
if (fs.existsSync(outputDir)) {
562564
const entries = fs.readdirSync(outputDir, { withFileTypes: true });
563565
for (const entry of entries) {
@@ -576,6 +578,32 @@ function main() {
576578
fs.mkdirSync(dataOutputDir, { recursive: true });
577579
fs.mkdirSync(uiOutputDir, { recursive: true });
578580

581+
// Create _category_.json files for proper sidebar labels
582+
fs.writeFileSync(
583+
path.join(uiOutputDir, FILE_EXTENSIONS.CATEGORY_CONFIG),
584+
`${JSON.stringify(
585+
{
586+
label: "UI components",
587+
position: 2,
588+
},
589+
null,
590+
2,
591+
)}\n`,
592+
MARKDOWN.FILE_ENCODING,
593+
);
594+
fs.writeFileSync(
595+
path.join(dataOutputDir, FILE_EXTENSIONS.CATEGORY_CONFIG),
596+
`${JSON.stringify(
597+
{
598+
label: "Data components",
599+
position: 3,
600+
},
601+
null,
602+
2,
603+
)}\n`,
604+
MARKDOWN.FILE_ENCODING,
605+
);
606+
579607
let count = 0;
580608

581609
const fileNameCounts = new Map<string, number>();

0 commit comments

Comments
 (0)