Skip to content

Commit a9e4912

Browse files
authored
Merge pull request #290 from HarperDB/category-index-sidebar-filter
filter index of some id from category with index doc link
2 parents 8fd732b + e9125af commit a9e4912

File tree

7 files changed

+70
-19
lines changed

7 files changed

+70
-19
lines changed

docs/reference/_category_.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
{
2-
"label": "Reference",
3-
"position": 4,
42
"link": {
5-
"type": "generated-index",
6-
"title": "Reference Documentation",
7-
"description": "Reference documentation and technical specifications",
8-
"keywords": ["reference", "specifications"]
3+
"type": "doc",
4+
"id": "reference/index"
95
}
106
}

docusaurus.config.ts

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,65 @@ const config: Config = {
8383
includeCurrentVersion: false,
8484
versions: {
8585
'4.6': {
86-
banner: 'none', // No banner for this version
86+
// No banner for 4.6 as its the latest version
87+
banner: 'none',
8788
},
8889
'4.5': {
8990
// No banner for 4.5 as its still actively maintained
9091
banner: 'none',
9192
},
9293
},
94+
// Converts npm commands in markdown code blocks to show npm/yarn/pnpm tabs
9395
remarkPlugins: [[require('@docusaurus/remark-plugin-npm2yarn'), { sync: true }]],
96+
// Filter out index files that are used as category links
97+
async sidebarItemsGenerator({ defaultSidebarItemsGenerator, ...args }) {
98+
const sidebarItems = await defaultSidebarItemsGenerator(args);
99+
100+
// Function to recursively process sidebar items
101+
function filterIndexFiles(items: any[]): any[] {
102+
return items
103+
.filter((item) => {
104+
// Filter out index.md files at the root of autogenerated directories
105+
// when they would be duplicates of category links
106+
if (item.type === 'doc' && item.id?.endsWith('/index')) {
107+
// Check if the category metadata has a link to this index
108+
const dirName = args.item?.dirName;
109+
if (dirName && item.id === `${dirName}/index`) {
110+
const categoryMeta = args.categoriesMetadata?.[dirName];
111+
if (categoryMeta?.link?.type === 'doc' && categoryMeta.link.id === item.id) {
112+
const versionName = args.version?.versionName || 'current';
113+
console.log(`✂️ 🔗 [v${versionName}] Removing ${item.id} from ${dirName} (category link exists)`);
114+
return false;
115+
}
116+
}
117+
// Keep other index files that are in subcategories
118+
return true;
119+
}
120+
121+
// Process categories recursively
122+
if (item.type === 'category' && item.items) {
123+
return {
124+
...item,
125+
items: filterIndexFiles(item.items),
126+
};
127+
}
128+
129+
return true;
130+
})
131+
.map((item) => {
132+
// For categories, recursively filter their items
133+
if (item.type === 'category' && item.items) {
134+
return {
135+
...item,
136+
items: filterIndexFiles(item.items),
137+
};
138+
}
139+
return item;
140+
});
141+
}
142+
143+
return filterIndexFiles(sidebarItems);
144+
},
94145
},
95146
],
96147

sidebars.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ const sidebars: SidebarsConfig = {
4545
{
4646
type: 'category',
4747
label: 'Reference',
48+
link: {
49+
type: 'doc',
50+
id: 'reference/index',
51+
},
4852
items: [{ type: 'autogenerated', dirName: 'reference' }],
4953
},
5054
],
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
{
2-
"label": "Reference",
3-
"position": 4,
42
"link": {
5-
"type": "generated-index",
6-
"title": "Reference Documentation",
7-
"description": "Reference documentation and technical specifications",
8-
"keywords": ["reference", "specifications"]
3+
"type": "doc",
4+
"id": "reference/index"
95
}
106
}
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
{
2-
"label": "Reference",
3-
"position": 4,
42
"link": {
5-
"type": "generated-index",
6-
"title": "Reference Documentation",
7-
"description": "Reference documentation and technical specifications",
8-
"keywords": ["reference", "specifications"]
3+
"type": "doc",
4+
"id": "reference/index"
95
}
106
}

versioned_sidebars/version-4.5-sidebars.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@
5252
{
5353
"type": "category",
5454
"label": "Reference",
55+
"link": {
56+
"type": "doc",
57+
"id": "reference/index"
58+
},
5559
"items": [
5660
{
5761
"type": "autogenerated",

versioned_sidebars/version-4.6-sidebars.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@
5252
{
5353
"type": "category",
5454
"label": "Reference",
55+
"link": {
56+
"type": "doc",
57+
"id": "reference/index"
58+
},
5559
"items": [
5660
{
5761
"type": "autogenerated",

0 commit comments

Comments
 (0)