Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(remix-dev): suport handle in frontmatter #4865

Merged
merged 3 commits into from
Jan 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/smart-doors-sing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"remix": patch
"@remix-run/dev": patch
---

suport `handle` in md(x) frontmatter
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