Skip to content

Commit

Permalink
feat(remix-dev): set handle from frontmatter in MDX files
Browse files Browse the repository at this point in the history
Fixes #4864.
  • Loading branch information
lpsinger committed Jan 4, 2023
1 parent 2c398e4 commit 0a7afc8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
9 changes: 4 additions & 5 deletions docs/guides/mdx.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
---
Expand All @@ -77,6 +77,9 @@ meta:

headers:
Cache-Control: no-cache

handle:
someData: abc
---

import styles from "./first-post.css";
Expand All @@ -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";

Expand Down
6 changes: 2 additions & 4 deletions integration/mdx-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ test.describe("mdx", () => {
meta:
title: My First Post
description: Isn't this awesome?
handle:
someData: abc
headers:
Cache-Control: no-cache
---
Expand All @@ -63,10 +65,6 @@ export const links = () => [
{ rel: "stylesheet", href: "app.css" }
]
export const handle = {
someData: "abc"
}
import { useLoaderData } from '@remix-run/react';
export const loader = async () => {
Expand Down
1 change: 1 addition & 0 deletions packages/remix-dev/compiler/plugins/mdx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down

0 comments on commit 0a7afc8

Please sign in to comment.