1+ import fs from 'fs' ;
2+
3+ /**
4+ * Generates a namespaced sidebar configuration based on the OpenRPC document
5+ */
6+ async function generateNamespacedSidebars ( ) {
7+ console . log ( 'Generating namespaced sidebars...' ) ;
8+
9+ // Read the OpenRPC document
10+ const openrpcData = JSON . parse ( fs . readFileSync ( 'refs-openrpc.json' , 'utf8' ) ) ;
11+
12+ // Read the method namespaces mapping
13+ const methodNamespaces = JSON . parse ( fs . readFileSync ( 'method-namespaces.json' , 'utf8' ) ) ;
14+
15+ // Group methods by namespace
16+ const namespaces = { } ;
17+
18+ openrpcData . methods . forEach ( method => {
19+ const methodName = method . name ;
20+ const namespace = methodNamespaces [ methodName ] || extractNamespace ( methodName ) ;
21+ if ( ! namespaces [ namespace ] ) {
22+ namespaces [ namespace ] = [ ] ;
23+ }
24+ namespaces [ namespace ] . push ( methodName ) ;
25+ } ) ;
26+
27+ // Make sure directory exists
28+ if ( ! fs . existsSync ( 'docs/reference/json-rpc' ) ) {
29+ fs . mkdirSync ( 'docs/reference/json-rpc' , { recursive : true } ) ;
30+ }
31+
32+ // Add custom JSON-RPC reference sidebar to docs
33+ fs . writeFileSync ( 'docs/reference/json-rpc/eth-namespace.md' , generateSidebarPage ( 'ETH Namespace' , namespaces [ 'eth' ] || [ ] ) ) ;
34+ fs . writeFileSync ( 'docs/reference/json-rpc/debug-namespace.md' , generateSidebarPage ( 'Debug Namespace' , namespaces [ 'debug' ] || [ ] ) ) ;
35+ fs . writeFileSync ( 'docs/reference/json-rpc/engine-namespace.md' , generateSidebarPage ( 'Engine Namespace' , namespaces [ 'engine' ] || [ ] ) ) ;
36+
37+ // Create a sidebar introduction page
38+ fs . writeFileSync ( 'docs/reference/json-rpc/introduction.md' , generateIntroductionPage ( Object . keys ( namespaces ) ) ) ;
39+
40+ console . log ( 'Namespaced sidebar files generated successfully!' ) ;
41+ }
42+
43+ /**
44+ * Extracts namespace from method name (e.g., eth_blockNumber -> eth)
45+ */
46+ function extractNamespace ( methodName ) {
47+ if ( ! methodName ) return 'other' ;
48+
49+ const parts = methodName . split ( '_' ) ;
50+ if ( parts . length > 1 ) {
51+ return parts [ 0 ] ;
52+ }
53+
54+ return 'other' ;
55+ }
56+
57+ /**
58+ * Generates a markdown page for a specific namespace
59+ */
60+ function generateSidebarPage ( title , methods ) {
61+ const sortedMethods = [ ...methods ] . sort ( ) ;
62+
63+ return `---
64+ sidebar_position: 1
65+ ---
66+
67+ # ${ title }
68+
69+ This page lists all JSON-RPC methods in the ${ title . toLowerCase ( ) } .
70+
71+ ${ sortedMethods . map ( method => `- [${ method } ](/reference/${ method } )` ) . join ( '\n' ) }
72+ ` ;
73+ }
74+
75+ /**
76+ * Generates an introduction page for JSON-RPC API
77+ */
78+ function generateIntroductionPage ( namespaces ) {
79+ return `---
80+ sidebar_position: 1
81+ ---
82+
83+ # JSON-RPC API Introduction
84+
85+ The Ethereum JSON-RPC API is organized into several namespaces, each containing related methods:
86+
87+ ${ namespaces . map ( namespace => `- [${ namespace . charAt ( 0 ) . toUpperCase ( ) + namespace . slice ( 1 ) } Namespace](/reference/json-rpc/${ namespace } -namespace)` ) . join ( '\n' ) }
88+
89+ Each namespace contains methods with specific functionality related to different aspects of Ethereum node operation.
90+ ` ;
91+ }
92+
93+ generateNamespacedSidebars ( ) . catch ( console . error ) ;
0 commit comments