@@ -67,36 +67,50 @@ let groupBySection = mdxPages =>
67
67
acc
68
68
})
69
69
70
- let convertToNavItems = items =>
70
+ let convertToNavItems = ( items , rootPath ) =>
71
71
Array .map (items , (item ): SidebarLayout .Sidebar .NavItem .t => {
72
72
{
73
73
name : item .title ,
74
- href : item .canonical , // TODO: RR7 - canonical works for now, but we should make this more robust so that it's not required
74
+ href : ` ${rootPath}/${ item.slug}` ,
75
75
}
76
76
})
77
77
78
78
let filterMdxPages = (mdxPages , path ) =>
79
79
Array .filter (mdxPages , mdx => (mdx .path :> string )-> String .includes (path ))
80
80
81
+ let getGroup = (groups , groupName ): SidebarLayout .Sidebar .Category .t => {
82
+ {
83
+ name : groupName ,
84
+ items : groups
85
+ -> Dict .get (groupName )
86
+ -> Option .getOr ([]),
87
+ }
88
+ }
89
+
90
+ let getAllGroups = (groups , groupNames ): array <SidebarLayout .Sidebar .Category .t > =>
91
+ groupNames -> Array .map (item => getGroup (groups , item ))
92
+
81
93
// These are the pages for the language manual, sorted by their "order" field in the frontmatter
82
94
let manualTableOfContents = () => {
83
95
let groups =
84
96
allMdx
85
97
-> filterMdxPages ("docs/manual" )
86
98
-> groupBySection
87
- -> Dict .mapValues (values => values -> sortSection -> convertToNavItems )
88
-
89
- // Console.log(groups)
99
+ -> Dict .mapValues (values => values -> sortSection -> convertToNavItems ("/docs/manual" ))
90
100
91
101
// these are the categories that appear in the sidebar
92
- let categories : array <SidebarLayout .Sidebar .Category .t > = [
93
- {name : "Overview" , items : groups -> Dict .getUnsafe ("Overview" )},
94
- {name : "Guides" , items : groups -> Dict .getUnsafe ("Guides" )},
95
- {name : "Language Features" , items : groups -> Dict .getUnsafe ("Language Features" )},
96
- {name : "JavaScript Interop" , items : groups -> Dict .getUnsafe ("JavaScript Interop" )},
97
- {name : "Build System" , items : groups -> Dict .getUnsafe ("Build System" )},
98
- {name : "Advanced Features" , items : groups -> Dict .getUnsafe ("Advanced Features" )},
99
- ]
102
+ let categories : array <SidebarLayout .Sidebar .Category .t > = getAllGroups (
103
+ groups ,
104
+ [
105
+ "Overview" ,
106
+ "Guides" ,
107
+ "Language Features" ,
108
+ "JavaScript Interop" ,
109
+ "Build System" ,
110
+ "Advanced Features" ,
111
+ ],
112
+ )
113
+
100
114
categories
101
115
}
102
116
@@ -105,17 +119,13 @@ let reactTableOfContents = () => {
105
119
allMdx
106
120
-> filterMdxPages ("docs/react" )
107
121
-> groupBySection
108
- -> Dict .mapValues (values => values -> sortSection -> convertToNavItems )
109
-
110
- Console .log (groups )
122
+ -> Dict .mapValues (values => values -> sortSection -> convertToNavItems ("/docs/react" ))
111
123
112
124
// these are the categories that appear in the sidebar
113
- let categories : array <SidebarLayout .Sidebar .Category .t > = [
114
- {name : "Overview" , items : groups -> Dict .getUnsafe ("Overview" )},
115
- // {name: "Main concepts", items: groups->Dict.getUnsafe("Main concepts")},
116
- ]
117
-
118
- Console .log (categories )
125
+ let categories : array <SidebarLayout .Sidebar .Category .t > = getAllGroups (
126
+ groups ,
127
+ ["Overview" , "Main Concepts" , "Hooks & State Management" , "Guides" , "Extra" ],
128
+ )
119
129
120
130
categories
121
131
}
@@ -125,9 +135,7 @@ let apiTableOfContents = () => {
125
135
allMdx
126
136
-> filterMdxPages ("docs/manual/api" )
127
137
-> groupBySection
128
- -> Dict .mapValues (values => values -> sortSection -> convertToNavItems )
129
-
130
- // Console.log(groups)
138
+ -> Dict .mapValues (values => values -> sortSection -> convertToNavItems ("/docs/manual/api" ))
131
139
132
140
// these are the categories that appear in the sidebar
133
141
let categories : array <SidebarLayout .Sidebar .Category .t > = [
@@ -142,7 +150,7 @@ let apiTableOfContents = () => {
142
150
143
151
let loader : Loader .t <loaderData > = async ({request }) => {
144
152
let {pathname } = WebAPI .URL .make (~url = request .url )
145
- Console . log ( pathname )
153
+
146
154
let mdx = await loadMdx (request , ~options = {remarkPlugins : [Mdx .gfm ]})
147
155
148
156
// TODO: actually render the blog pages
@@ -158,7 +166,6 @@ let loader: Loader.t<loaderData> = async ({request}) => {
158
166
} else {
159
167
let categories = {
160
168
if pathname -> String .includes ("docs/manual/api" ) {
161
- Console .log (apiTableOfContents ())
162
169
apiTableOfContents ()
163
170
} else if pathname -> String .includes ("docs/manual" ) {
164
171
manualTableOfContents ()
0 commit comments