diff --git a/.yarn/patches/react-router-mdx-npm-1.0.8-d4402c3003.patch b/.yarn/patches/react-router-mdx-npm-1.0.8-d4402c3003.patch deleted file mode 100644 index 6b1496b84..000000000 --- a/.yarn/patches/react-router-mdx-npm-1.0.8-d4402c3003.patch +++ /dev/null @@ -1,40 +0,0 @@ -diff --git a/dist/server/index.js b/dist/server/index.js -index 1e56a6c..b323b05 100644 ---- a/dist/server/index.js -+++ b/dist/server/index.js -@@ -59,15 +59,15 @@ import matter from "gray-matter"; - import { compile as compileMdx } from "@mdx-js/mdx"; - import remarkFrontmatter from "remark-frontmatter"; - var compile = async (content, options) => { -- const compiled = await compileMdx(content, { -+ const compiled = await compileMdx({ value: content, path: options?.path }, { - ...options ?? {}, - outputFormat: "function-body", -- remarkPlugins: [remarkFrontmatter, ...options?.remarkPlugins ?? []] -- }); -+ remarkPlugins: [remarkFrontmatter, ...options?.remarkPlugins ?? []], -+ },); - return String(compiled); - }; - var getAttributes = (content) => { -- const { data: attributes } = matter(content); -+ const { data: attributes, } = matter(content); - return attributes; - }; - -@@ -119,12 +119,13 @@ var loadMdx = async (request, options) => { - const path = getFilePathBasedOnUrl(request.url, paths, aliases); - const content = await getFileContent(path); - const [mdxContent, attributes] = await Promise.all([ -- compile(content, options), -+ compile(content, { ...options, path }), - getAttributes(content) - ]); - return { - __raw: mdxContent, -- attributes -+ attributes, -+ path - }; - }; - var loadAllMdx = async (filterByPaths) => { diff --git a/app/routes.res b/app/routes.res index dfa1295a2..bd6e36e13 100644 --- a/app/routes.res +++ b/app/routes.res @@ -59,27 +59,6 @@ let syntaxLookupDetailRoutes = route(path, "./routes/SyntaxLookupDetailRoute.jsx", ~options={id: path}) ) -let mdxRoutes = mdxRoutes("./routes/MdxRoute.jsx")->Array.filter(r => - !( - r.path - ->Option.map(path => - path === "blog" || - String.startsWith(path, "blog/") || - path === "docs/manual" || - String.startsWith(path, "docs/manual/") || - path === "docs/react" || - String.startsWith(path, "docs/react/") || - path === "docs/guidelines" || - String.startsWith(path, "docs/guidelines/") || - path === "community" || - String.startsWith(path, "community/") || - path === "syntax-lookup" || - String.startsWith(path, "syntax-lookup/") - ) - ->Option.getOr(false) - ) -) - let default = [ index("./routes/LandingPageRoute.jsx"), route("packages", "./routes/PackagesRoute.jsx"), @@ -101,6 +80,5 @@ let default = [ ...docsGuidelinesRoutes, ...communityRoutes, ...syntaxLookupDetailRoutes, - ...mdxRoutes, route("*", "./routes/NotFoundRoute.jsx"), ] diff --git a/app/routes/BlogRoute.res b/app/routes/BlogRoute.res index 7d7745226..d3999e6f4 100644 --- a/app/routes/BlogRoute.res +++ b/app/routes/BlogRoute.res @@ -3,8 +3,7 @@ type loaderData = {posts: array, category: Blog.category} let loader: ReactRouter.Loader.t = async ({request}) => { let showArchived = request.url->String.includes("archived") let posts = async () => - (await Mdx.allMdx(~filterByPaths=["markdown-pages/blog"])) - ->Mdx.filterMdxPages("blog") + (await MdxFile.loadAllAttributes(~dir="markdown-pages/blog")) ->Array.map(BlogLoader.transform) ->Array.toSorted((a, b) => { a.frontmatter.date->DateStr.toDate > b.frontmatter.date->DateStr.toDate ? -1.0 : 1.0 diff --git a/app/routes/MdxRoute.res b/app/routes/MdxRoute.res deleted file mode 100644 index bebae0b1d..000000000 --- a/app/routes/MdxRoute.res +++ /dev/null @@ -1,187 +0,0 @@ -open Mdx - -type loaderData = { - ...Mdx.t, - categories: array, - entries: array, - breadcrumbs?: list, - title: string, - filePath: option, -} - -let loader: ReactRouter.Loader.t = async ({request}) => { - let {pathname} = WebAPI.URL.make(~url=request.url) - - let mdx = await loadMdx(request, ~options={remarkPlugins: Mdx.plugins}) - - let categories = [] - - let filePath = ref(None) - - let fileContents = await (await allMdx()) - ->Array.filter(mdx => { - switch (mdx.slug, mdx.canonical) { - // Having a canonical path is the best way to ensure we get the right file - | (_, Nullable.Value(canonical)) => pathname == (canonical :> string) - // if we don't have a canonical path, see if we can find the slug in the pathname - | (Some(slug), _) => pathname->String.includes(slug) - // otherwise we can't match it and the build should fail - | _ => false - } - }) - ->Array.get(0) - ->Option.flatMap(mdx => { - filePath := - mdx.path->Option.map(mdxPath => - String.slice(mdxPath, ~start=mdxPath->String.indexOf("rescript-lang.org/") + 17) - ) - // remove the filesystem path to get the relative path to the files in the repo - mdx.path - }) - ->Option.map(path => Node.Fs.readFile(path, "utf-8")) - ->Option.getOrThrow(~message="Could not find MDX file for path " ++ (pathname :> string)) - - let markdownTree = Mdast.fromMarkdown(fileContents) - let tocResult = Mdast.toc(markdownTree, {maxDepth: 2}) - - let headers = Dict.make() - - Mdast.reduceHeaders(tocResult.map, headers) - - let entries = - headers - ->Dict.toArray - ->Array.map(((header, url)): TableOfContents.entry => { - header, - href: (url :> string), - }) - ->Array.slice(~start=2) // skip first two entries which are the document entry and the H1 title for the page, we just want the h2 sections - - let breadcrumbs = - pathname->String.includes("docs/manual") - ? Some(list{ - {Url.name: "Docs", href: "/docs/"}, - { - Url.name: "Language Manual", - href: "/docs/manual/" ++ "introduction", - }, - }) - : None - - let metaTitleCategory = { - let path = (pathname :> string) - if path->String.includes("docs/manual") { - "ReScript Language Manual" - } else { - "ReScript" - } - } - - let title = mdx.attributes.title - - let res: loaderData = { - __raw: mdx.__raw, - attributes: mdx.attributes, - entries, - categories, - ?breadcrumbs, - title: `${title} | ${metaTitleCategory}`, - filePath: filePath.contents, - } - res -} - -let default = () => { - let {pathname} = ReactRouter.useLocation() - let component = useMdxComponent() - let attributes = useMdxAttributes() - - let loaderData: loaderData = ReactRouter.useLoaderData() - - let {entries, categories, title} = loaderData - - <> - {if ( - (pathname :> string)->String.includes("docs/manual") || - (pathname :> string)->String.includes("docs/react") - ) { - <> - Nullable.getOr("")} /> - - { - let breadcrumbs = loaderData.breadcrumbs->Option.map(crumbs => - List.mapWithIndex(crumbs, (item, index) => { - if index === 0 { - if (pathname :> string)->String.includes("docs/manual") { - {...item, href: "/docs/manual/introduction"} - } else { - item - } - } else { - item - } - }) - ) - let editHref = `https://github.com/rescript-lang/rescript-lang.org/blob/master${loaderData.filePath->Option.getOrThrow}` - - let sidebarContent = - - - <> - - {breadcrumbs->Option.mapOr(React.null, crumbs => - - )} - - {React.string("Edit")} - - - -
{component()}
-
- - } - - } else { - React.null - }} - -} diff --git a/app/routes/MdxRoute.resi b/app/routes/MdxRoute.resi deleted file mode 100644 index 8e4a827fb..000000000 --- a/app/routes/MdxRoute.resi +++ /dev/null @@ -1,14 +0,0 @@ -type loaderData = { - ...Mdx.t, - categories: array, - entries: array, - mdxSources?: array, - activeSyntaxItem?: SyntaxLookup.item, - breadcrumbs?: list, - title: string, - filePath: option, -} - -let loader: ReactRouter.Loader.t - -let default: unit => React.element diff --git a/app/routes/SyntaxLookupRoute.res b/app/routes/SyntaxLookupRoute.res index b2a0e8e25..11ddf738c 100644 --- a/app/routes/SyntaxLookupRoute.res +++ b/app/routes/SyntaxLookupRoute.res @@ -1,6 +1,4 @@ open ReactRouter -open Mdx - type loaderData = {mdxSources: array} let convert = (mdx: Mdx.attributes): SyntaxLookup.item => { @@ -16,14 +14,8 @@ let convert = (mdx: Mdx.attributes): SyntaxLookup.item => { } let loader: Loader.t = async _ => { - let allMdx = await Shims.runWithoutLogging(() => loadAllMdx()) - let mdxSources = - allMdx - ->Array.filter(page => - page.path->Option.map(String.includes(_, "syntax-lookup"))->Option.getOr(false) - ) - ->Array.map(convert) + (await MdxFile.loadAllAttributes(~dir="markdown-pages/syntax-lookup"))->Array.map(convert) { mdxSources: mdxSources, diff --git a/generate-route-types.mjs b/generate-route-types.mjs index 1d36da5a0..9d9d80e02 100644 --- a/generate-route-types.mjs +++ b/generate-route-types.mjs @@ -1,15 +1,4 @@ import fs from "fs/promises"; -import { init } from "react-router-mdx/server"; - -init({ - paths: [ - "markdown-pages/blog", - "markdown-pages/docs", - "markdown-pages/community", - "markdown-pages/syntax-lookup", - ], - aliases: ["blog", "docs", "community", "syntax-lookup"], -}); const { default: routes } = await import("./app/routes.mjs"); diff --git a/package.json b/package.json index 8f43a6852..97b17d89e 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,6 @@ "react-markdown": "^10.1.0", "react-router": "^7.12.0", "react-router-dom": "^7.9.4", - "react-router-mdx": "patch:react-router-mdx@npm%3A1.0.8#~/.yarn/patches/react-router-mdx-npm-1.0.8-d4402c3003.patch", "rehype-slug": "^6.0.0", "rehype-stringify": "^10.0.1", "remark": "^15.0.1", diff --git a/react-router.config.mjs b/react-router.config.mjs index ddb22da04..5e52df970 100644 --- a/react-router.config.mjs +++ b/react-router.config.mjs @@ -1,15 +1,4 @@ import * as fs from "node:fs"; -import { init } from "react-router-mdx/server"; - -const mdx = init({ - paths: [ - "markdown-pages/blog", - "markdown-pages/docs", - "markdown-pages/community", - "markdown-pages/syntax-lookup", - ], - aliases: ["blog", "docs", "community", "syntax-lookup"], -}); const { stdlibPaths } = await import("./app/routes.jsx"); @@ -17,11 +6,7 @@ export default { ssr: false, async prerender({ getStaticPaths }) { - return [ - ...(await getStaticPaths()), - ...(await mdx.paths()), - ...stdlibPaths, - ]; + return [...(await getStaticPaths()), ...stdlibPaths]; }, buildEnd: async () => { fs.cpSync("./build/client", "./out", { recursive: true }); diff --git a/src/Mdx.res b/src/Mdx.res index b7840e20e..9eccb018a 100644 --- a/src/Mdx.res +++ b/src/Mdx.res @@ -47,23 +47,6 @@ type remarkPlugin type tree -type loadMdxOptions = {remarkPlugins?: array} - -@module("react-router-mdx/server") -external loadMdx: (WebAPI.FetchAPI.request, ~options: loadMdxOptions=?) => promise = "loadMdx" - -@module("react-router-mdx/client") -external useMdxAttributes: unit => attributes = "useMdxAttributes" - -@module("react-router-mdx/client") -external useMdxComponent: (~components: {..}=?) => Jsx.component<'a> = "useMdxComponent" - -@module("react-router-mdx/server") -external loadAllMdx: (~filterByPaths: array=?) => promise> = "loadAllMdx" - -@module("react-router-mdx/client") -external useMdxFiles: unit => {..} = "useMdxFiles" - @module("remark-gfm") external gfm: remarkPlugin = "default" @@ -73,11 +56,6 @@ external validateLinks: remarkPlugin = "default" @module("mdast-util-to-string") external childrenToString: {..} => string = "toString" -// The loadAllMdx function logs out all of the file contents as it reads them, which is noisy and not useful. -// We can suppress that logging with this helper function. -let allMdx = async (~filterByPaths: option>=?) => - await Shims.runWithoutLogging(() => loadAllMdx(~filterByPaths?)) - let sortSection = mdxPages => Array.toSorted(mdxPages, (a: attributes, b: attributes) => switch (a.order, b.order) { diff --git a/src/bindings/ReactRouter.res b/src/bindings/ReactRouter.res index 9aa991f79..194d31343 100644 --- a/src/bindings/ReactRouter.res +++ b/src/bindings/ReactRouter.res @@ -114,9 +114,6 @@ module Routes = { @module("@react-router/dev/routes") external layout: (string, array) => t = "layout" - - @module("react-router-mdx/server") - external mdxRoutes: string => array = "routes" } module BrowserRouter = {