Comments (6)
Apologies if this is the wrong issue to raise this, but it felt somewhat related – I'd love to be able to access these attributes
(or frontmatter
) within the layout wrapping my MDX routes
Something like…
---
title: "Do Not Disturb"
date: "2019-01-03"
description: "Modern mindfulness tips for connected life"
---
Some markdown content nested within `app/routes/blog/`
// app/routes/blog.tsx
import { Outlet, useLoaderData } from "remix";
import type { LoaderFunction } from "remix";
export const loader: LoaderFunction = async ({ attributes }) => {
return { attributes };
};
export default function BlogPost() {
const { attributes } = useLoaderData();
return (
<article>
<header>
<h1>{attributes.title}</h1>
<p>{attributes.description}</p>
</header>
<Outlet />
</article>
);
}
This feels a bit more akin to Remix layouts, and would also open up the door to more server-side logic in MDX posts (e.g. creating an image placeholder on the server-side for a hero image. Heck! If content
was available too, I could even create placeholders for all MDX images on the server-side)
from remix.
I think I could get behind this.
This code is no different, but feels less magic when you explicitly write it out like this:
---
meta:
title: Remix Rocks
description: A solid description of this document.
---
This is the content for the blog post
export default ({ attributes, body }) => (
<div>
<h1>{attributes.meta.title}</h1>
<article>{body}</article>
</div>
)
So by default, the default export is the body of the markdown as a component. If you export default, then that's the component we'll use, and Remix passes the attributes and body to you.
To complete the picture but in reverse, mdx components export the attributes:
import MdxPage, { attributes } from "../mdx/some-page";
export default function Page() {
return (
<div>
<h1>{attributes.title}</h1>
<MdxPage />
</div>
);
}
WDYT?
from remix.
Big fan of calling this frontmatter
/adding support for this!
from remix.
been thinking about this too, have you done this elsewhere? what does SlimLayout look like?
from remix.
It's not much right now. But I'd like to have access to frontmatter.
import * as React from 'react'
import {Link} from 'react-router-dom'
function SlimLayout({
children,
...props
}: React.PropsWithChildren<{}>): React.ReactNode {
console.log(props) // <-- I want the frontmatter in there
return (
<div>
<nav>
<ul>
<li>
<Link to="/">kentcdodds.com</Link>
</li>
</ul>
</nav>
<main>{children}</main>
<footer>Join the newsletter!</footer>
</div>
)
}
export {SlimLayout}
from remix.
I like that!
Could we call it frontmatter
instead of attributes
? That's consistent with the common term for the "YAML at the top of markdown" I think.
from remix.
Related Issues (20)
- Wrong type in `LayoutComponent` exported from `@remix-run/react` HOT 1
- Hosting Remix + Vite on Vercel: `Cannot find package '@remix-run/dev' imported from /vercel/path0/vite.config.ts.timestamp-[number].mjs` HOT 8
- Requested module 'use-query-params' is a CommonJS module HOT 3
- Link with button on top still triggers HOT 11
- Hydration errors with `export Layout` in root HOT 3
- remix vite:dev via npm run in workspace causes error when cancelled
- encoded character in url causes "Initial URL does not match URL at time of hydration" HOT 2
- Type mismatch when returning from useLoaderData HOT 6
- Streaming Breaks on Firefox
- Ignore `.tsbuildinfo` files from publishing to npm
- SPA Mode: get invalid HTML when `HydrateFallback` is omitted (using `Layout`) HOT 2
- SPA Mode: `remix reveal` generate entries files with unexpected content HOT 8
- cannot create a /server route HOT 2
- Error boundary not rendered inside component with `clientLoader.hydrate`
- Manifest is not created if `buildDirectory` is set to `lib` HOT 3
- [Vite] Noisy error “Module level directives cause errors when bundled, "use client" was ignored.” when running `remix vite:build` on a project that includes a dependency file which includes the `"use client"` directive. HOT 4
- Vite template doesn't detect the `.server` modules HOT 1
- Remix returns a 500 for POST requests against routes without an action instead of a 405 HOT 1
- SSR not working with the new Vite Cloudflare template on Cloudflare Pages HOT 4
- Redirects silently fail to a route that has an import error
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from remix.