@@ -5,6 +5,7 @@ type loaderData = {
55 ... Mdx .t ,
66 categories : array <SidebarLayout .Sidebar .Category .t >,
77 entries : array <TableOfContents .entry >,
8+ blogPost ?: BlogApi .post ,
89}
910
1011/**
@@ -43,30 +44,6 @@ let components = {
4344 "Warn" : Markdown .Warn .make ,
4445}
4546
46- // The loadAllMdx function logs out all of the file contents as it reads them, which is noisy and not useful.
47- // We can suppress that logging with this helper function.
48- let allMdx = await Shims .runWithoutLogging (() => loadAllMdx ())
49-
50- let sortSection = mdxPages =>
51- Array .toSorted (mdxPages , (a : Mdx .attributes , b : Mdx .attributes ) =>
52- switch (a .order , b .order ) {
53- | (Some (a ), Some (b )) => a > b ? 1.0 : - 1.0
54- | _ => - 1.0
55- }
56- )
57-
58- let groupBySection = mdxPages =>
59- Array .reduce (mdxPages , (Dict .make () :> Dict .t <array <Mdx .attributes >>), (acc , item ) => {
60- let section = item .section -> Option .flatMap (Dict .get (acc , _ ))
61- switch section {
62- // If the section already exists, add this item to it
63- | Some (section ) => section -> Array .push (item )
64- // otherwise create a new section with this item
65- | None => item .section -> Option .forEach (section => acc -> Dict .set (section , [item ]))
66- }
67- acc
68- })
69-
7047let convertToNavItems = (items , rootPath ) =>
7148 Array .map (items , (item ): SidebarLayout .Sidebar .NavItem .t => {
7249 {
@@ -75,9 +52,6 @@ let convertToNavItems = (items, rootPath) =>
7552 }
7653 })
7754
78- let filterMdxPages = (mdxPages , path ) =>
79- Array .filter (mdxPages , mdx => (mdx .path :> string )-> String .includes (path ))
80-
8155let getGroup = (groups , groupName ): SidebarLayout .Sidebar .Category .t => {
8256 {
8357 name : groupName ,
@@ -134,6 +108,8 @@ let reactTableOfContents = () => {
134108 categories
135109}
136110
111+ let posts = () => allMdx -> filterMdxPages ("blog" )-> Array .map (BlogLoader .transform )
112+
137113let loader : Loader .t <loaderData > = async ({request }) => {
138114 let {pathname } = WebAPI .URL .make (~url = request .url )
139115
@@ -143,13 +119,12 @@ let loader: Loader.t<loaderData> = async ({request}) => {
143119 if pathname -> String .includes ("blog" ) {
144120 let posts = blogPosts ()
145121
146- Console .log2 ("posts" , posts )
147-
148122 let res : loaderData = {
149123 __raw : mdx .__raw ,
150124 attributes : mdx .attributes ,
151125 entries : [],
152126 categories : [],
127+ blogPost : mdx .attributes -> BlogLoader .transform ,
153128 }
154129
155130 res
@@ -207,8 +182,11 @@ let default = () => {
207182 let component = useMdxComponent (~components )
208183 let attributes = useMdxAttributes ()
209184
210- let {categories , entries } = useLoaderData ()
185+ let loaderData : loaderData = useLoaderData ()
186+
187+ let {entries , categories } = loaderData
211188
189+ // TODO: get actual meta categories working
212190 let metaTitleCategory =
213191 (pathname :> string )-> String .includes ("docs/manual" )
214192 ? "ReScript Language Manual"
@@ -226,8 +204,13 @@ let default = () => {
226204 <div className = "markdown-body" > {component ()} </div >
227205 </DocsLayout >
228206 } else {
229- // TODO Handle blog pages
230- React .null
207+ switch loaderData .blogPost {
208+ | Some ({frontmatter , archived , path }) => {
209+ Console .log (frontmatter )
210+ <BlogArticle frontmatter isArchived = archived path > {component ()} </BlogArticle >
211+ }
212+ | None => React .null // TODO: RR7 show an error
213+ }
231214 }}
232215 </>
233216
0 commit comments