File tree Expand file tree Collapse file tree 3 files changed +33
-13
lines changed
src/components/ExampleShowcase Expand file tree Collapse file tree 3 files changed +33
-13
lines changed Original file line number Diff line number Diff line change 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" ,
Original file line number Diff line number Diff line change 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+
1529const 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} ;
Original file line number Diff line number Diff 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 ) } >
You can’t perform that action at this time.
0 commit comments