Skip to content

Commit 4a5cee1

Browse files
authored
Merge pull request #35 from drindr/intuitive-menu
add more intuitive menu for node and example pages
2 parents c548b73 + 606ad49 commit 4a5cee1

File tree

3 files changed

+33
-13
lines changed

3 files changed

+33
-13
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"@docusaurus/plugin-content-docs": "^3.2.0",
2626
"@docusaurus/preset-classic": "^3.2.0",
2727
"@docusaurus/theme-mermaid": "^3.2.0",
28+
"@docusaurus/theme-common": "^3.2.0",
2829
"@docusaurus/theme-search-algolia": "^3.2.0",
2930
"@fontsource/work-sans": "^5.0.18",
3031
"@popperjs/core": "^2.11.8",

sidebars.js

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,23 @@
99
Create as many sidebars as you want.
1010
*/
1111

12+
13+
import {readFileSync} from "fs";
14+
15+
function getCategories(path) {
16+
const fileContent = readFileSync(`${__dirname}/${path}`, 'utf8');
17+
const jsonData = JSON.parse(fileContent);
18+
return Array.from(new Set(jsonData.map(item => item.category)));
19+
}
20+
21+
const CategoriesExamples = getCategories("./src/data/examples.json");
22+
const CategoriesNodes = getCategories("./src/data/nodes.json");
23+
1224
// @ts-check
1325

1426
/** @type {import('@docusaurus/plugin-content-docs').SidebarsConfig} */
27+
28+
1529
const sidebars = {
1630
// By default, Docusaurus generates a sidebar from the docs folder structure
1731
// tutorialSidebar: [{ type: "autogenerated", dirName: "." }],
@@ -48,25 +62,29 @@ const sidebars = {
4862
type: "category",
4963
label: "Examples",
5064
link: { type: "doc", id: "examples/readme" },
51-
items: [
52-
{
53-
type: "autogenerated",
54-
dirName: "examples",
55-
},
56-
],
65+
items: CategoriesExamples.map((val) => {
66+
const dashVal = val.replaceAll(" ", "-");
67+
return {
68+
label: val,
69+
type: "link",
70+
href: `#${dashVal}`,
71+
};
72+
})
5773
},
5874
],
5975
nodes: [
6076
{
6177
type: "category",
6278
label: "Nodes",
6379
link: { type: "doc", id: "nodes/readme" },
64-
items: [
65-
{
66-
type: "autogenerated",
67-
dirName: "nodes",
68-
},
69-
],
80+
items: CategoriesNodes.map((val) => {
81+
const dashVal = val.replaceAll(" ", "-");
82+
return {
83+
label: val,
84+
type: "link",
85+
href: `#${dashVal}`,
86+
};
87+
})
7088
},
7189
],
7290
};

src/components/ExampleShowcase/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,12 +275,13 @@ function ShowcaseCards({
275275
let categoryUsers = filteredUsers.filter(
276276
(user) => user.category == category
277277
);
278+
let categoryDash = category.replace(/ /g, "-");
278279
if (categoryUsers.length === 0) {
279280
return null;
280281
}
281282
return (
282283
<div>
283-
<Heading as="h2" id={"#" + category}>
284+
<Heading as="h2" id={categoryDash}>
284285
{category}
285286
</Heading>
286287
<ul className={clsx("clean-list", styles.showcaseList)}>

0 commit comments

Comments
 (0)