From 8c8a94e9d75e2bd10b58ebddfa1de4001b4c55d0 Mon Sep 17 00:00:00 2001 From: Leo Singer Date: Wed, 14 Dec 2022 14:48:03 -0500 Subject: [PATCH] feat(remix-dev): set handle from frontmatter in MDX files Fixes #4864. --- docs/guides/mdx.md | 9 ++++----- packages/remix-dev/compiler/plugins/mdx.ts | 1 + 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/guides/mdx.md b/docs/guides/mdx.md index 40ac3ec3546..633dd18ad4b 100644 --- a/docs/guides/mdx.md +++ b/docs/guides/mdx.md @@ -67,7 +67,7 @@ You can reference your frontmatter data through "attributes". The title of this ### Advanced Example -You can even export all the other things in this module that you can in regular route modules in your mdx files like `loader` and `action`: +You can even export all the other things in this module that you can in regular route modules in your mdx files like `loader`, `action`, and `handle`: ```mdx --- @@ -77,6 +77,9 @@ meta: headers: Cache-Control: no-cache + +handle: + someData: abc --- import styles from "./first-post.css"; @@ -85,10 +88,6 @@ export const links = () => [ { rel: "stylesheet", href: styles }, ]; -export const handle = { - someData: "abc", -}; - import { json } from "@remix-run/node"; import { useLoaderData } from "@remix-run/react"; diff --git a/packages/remix-dev/compiler/plugins/mdx.ts b/packages/remix-dev/compiler/plugins/mdx.ts index 49e137b8a1a..6211dfa166e 100644 --- a/packages/remix-dev/compiler/plugins/mdx.ts +++ b/packages/remix-dev/compiler/plugins/mdx.ts @@ -72,6 +72,7 @@ export function mdxPlugin(config: RemixConfig): esbuild.Plugin { export const filename = ${JSON.stringify(path.basename(args.path))}; export const headers = typeof attributes !== "undefined" && attributes.headers; export const meta = typeof attributes !== "undefined" && attributes.meta; +export const handle = typeof attributes !== "undefined" && attributes.handle; `; let compiled = await xdm.compile(fileContents, {