@@ -67,36 +67,50 @@ let groupBySection = mdxPages =>
6767 acc
6868 })
6969
70- let convertToNavItems = items =>
70+ let convertToNavItems = ( items , rootPath ) =>
7171 Array .map (items , (item ): SidebarLayout .Sidebar .NavItem .t => {
7272 {
7373 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}` ,
7575 }
7676 })
7777
7878let filterMdxPages = (mdxPages , path ) =>
7979 Array .filter (mdxPages , mdx => (mdx .path :> string )-> String .includes (path ))
8080
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+
8193// These are the pages for the language manual, sorted by their "order" field in the frontmatter
8294let manualTableOfContents = () => {
8395 let groups =
8496 allMdx
8597 -> filterMdxPages ("docs/manual" )
8698 -> groupBySection
87- -> Dict .mapValues (values => values -> sortSection -> convertToNavItems )
88-
89- // Console.log(groups)
99+ -> Dict .mapValues (values => values -> sortSection -> convertToNavItems ("/docs/manual" ))
90100
91101 // 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+
100114 categories
101115}
102116
@@ -105,17 +119,13 @@ let reactTableOfContents = () => {
105119 allMdx
106120 -> filterMdxPages ("docs/react" )
107121 -> groupBySection
108- -> Dict .mapValues (values => values -> sortSection -> convertToNavItems )
109-
110- Console .log (groups )
122+ -> Dict .mapValues (values => values -> sortSection -> convertToNavItems ("/docs/react" ))
111123
112124 // 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+ )
119129
120130 categories
121131}
@@ -125,9 +135,7 @@ let apiTableOfContents = () => {
125135 allMdx
126136 -> filterMdxPages ("docs/manual/api" )
127137 -> groupBySection
128- -> Dict .mapValues (values => values -> sortSection -> convertToNavItems )
129-
130- // Console.log(groups)
138+ -> Dict .mapValues (values => values -> sortSection -> convertToNavItems ("/docs/manual/api" ))
131139
132140 // these are the categories that appear in the sidebar
133141 let categories : array <SidebarLayout .Sidebar .Category .t > = [
@@ -142,7 +150,7 @@ let apiTableOfContents = () => {
142150
143151let loader : Loader .t <loaderData > = async ({request }) => {
144152 let {pathname } = WebAPI .URL .make (~url = request .url )
145- Console . log ( pathname )
153+
146154 let mdx = await loadMdx (request , ~options = {remarkPlugins : [Mdx .gfm ]})
147155
148156 // TODO: actually render the blog pages
@@ -158,7 +166,6 @@ let loader: Loader.t<loaderData> = async ({request}) => {
158166 } else {
159167 let categories = {
160168 if pathname -> String .includes ("docs/manual/api" ) {
161- Console .log (apiTableOfContents ())
162169 apiTableOfContents ()
163170 } else if pathname -> String .includes ("docs/manual" ) {
164171 manualTableOfContents ()
0 commit comments