@@ -9,6 +9,7 @@ type loaderData = {
99 activeSyntaxItem ?: SyntaxLookup .item ,
1010 breadcrumbs ?: list <Url .breadcrumb >,
1111 title : string ,
12+ filePath : option <string >,
1213}
1314
1415/**
@@ -83,6 +84,10 @@ let blogPosts = async () => {
8384let manualTableOfContents = async () => {
8485 let groups =
8586 (await allMdx ())
87+ -> Array .map (item => {
88+ Console .log (item .path )
89+ item
90+ })
8691 -> filterMdxPages ("docs/manual" )
8792 -> groupBySection
8893 -> Dict .mapValues (values => values -> sortSection -> convertToNavItems ("/docs/manual" ))
@@ -147,6 +152,7 @@ let loader: ReactRouter.Loader.t<loaderData> = async ({request}) => {
147152 categories : [],
148153 blogPost : mdx .attributes -> BlogLoader .transform ,
149154 title : ` ${mdx.attributes.title} | ReScript Blog` ,
155+ filePath : None ,
150156 }
151157 res
152158 } else if pathname -> String .includes ("syntax-lookup" ) {
@@ -166,6 +172,7 @@ let loader: ReactRouter.Loader.t<loaderData> = async ({request}) => {
166172 mdxSources ,
167173 ?activeSyntaxItem ,
168174 title : mdx .attributes .title , // TODO RR7: check if this is correct
175+ filePath : None ,
169176 }
170177 res
171178 } else {
@@ -183,12 +190,18 @@ let loader: ReactRouter.Loader.t<loaderData> = async ({request}) => {
183190 }
184191 }
185192
193+ let filePath = ref (None )
194+
186195 // TODO POST RR7: extract this out into a separate function
187196 // it can probably be cached or something
188197 let fileContents = await (await allMdx ())
189198 -> Array .filter (mdx => (mdx .path :> string )-> String .includes (pathname ))
190199 -> Array .get (0 )
191- -> Option .map (mdx => mdx .path )
200+ -> Option .map (mdx => {
201+ filePath :=
202+ Some (mdx .path -> String .slice (~start = mdx .path -> String .indexOf ("rescript-lang.org/" ) + 17 )) // remove the filesystem path to get the relative path to the files in the repo
203+ mdx .path
204+ })
192205 -> Option .map (path => Node .Fs .readFile ((path :> string ), "utf-8" ))
193206 -> Option .getOrThrow
194207
@@ -257,6 +270,7 @@ let loader: ReactRouter.Loader.t<loaderData> = async ({request}) => {
257270 categories ,
258271 ?breadcrumbs ,
259272 title : ` ${title} | ${metaTitleCategory}` ,
273+ filePath : filePath .contents ,
260274 }
261275 res
262276 }
@@ -271,6 +285,8 @@ let default = () => {
271285
272286 let {entries , categories , title } = loaderData
273287
288+ Console .log2 ("Rendering MdxRoute for path:" , attributes )
289+
274290 <>
275291 {if (pathname :> string ) == "/docs/manual/api" {
276292 <>
@@ -289,8 +305,7 @@ let default = () => {
289305 categories
290306 activeToc = {title : "Introduction" , entries }
291307 breadcrumbs = ?loaderData .breadcrumbs
292- // TODO RR7: this probably needs to get the relative path
293- editHref = {` https://github.com/rescript-lang/rescript-lang.org/blob/master/pages/${attributes.path}.mdx` }
308+ editHref = {` https://github.com/rescript-lang/rescript-lang.org/blob/master${loaderData.filePath-> Option.getOrThrow}` }
294309 >
295310 <div className = "markdown-body pt-20 md:pt-0" > {component ()} </div >
296311 </DocsLayout >
0 commit comments