-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
[MDX] Fix remaining inconsistencies with Markdown #4268
Conversation
🦋 Changeset detectedLatest commit: bd9ee73 The changes in this PR will be included in the next version bump. This PR includes changesets to release 14 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
7eab1db
to
c36825e
Compare
packages/astro/src/@types/astro.ts
Outdated
export interface MarkdownLayoutProps<T extends Record<string, any>> { | ||
frontmatter: { file: string; url: string | undefined } & T; | ||
file: MarkdownInstance<T>['file']; | ||
url: MarkdownInstance<T>['url']; | ||
headings: MarkdownHeading[]; | ||
rawContent: MarkdownInstance<T>['rawContent']; | ||
compiledContent: MarkdownInstance<T>['compiledContent']; | ||
} | ||
|
||
export interface MDXLayoutProps<T> | ||
extends Omit<MarkdownLayoutProps<T>, 'rawContent' | 'compiledContent'> {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added these types for my own sanity. Could be pretty helpful! Example usage:
---
import type { MarkdownLayoutProps } from 'astro';
const { file, url, headings, frontmatter } = Astro.props as MarkdownLayoutProps<{ title: string }>;
---
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm good with these changes, just want to double check that this is really, seriously just a patch?
@@ -86,6 +84,8 @@ export default function markdown({ config, logging }: AstroPluginOptions): Plugi | |||
}; | |||
export async function Content() { | |||
const { layout, ...content } = frontmatter; | |||
content.file = file; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixes existing bug where frontmatter.file
and frontmatter.url
are added to glob
results as well. This is inconsistent with the previous API and type defs.
Changes
file
andurl
to frontmatter propsglob
<Content />
component exportrawContent
andcompiledContent
of typenever
. If called, this will log a helpful error message pointing to new frontmatter injection docs.*.mdx
to declared type moduleglob
to useMDXInstance
instead. This overrides therawContent
andcompiledContent
props to be typenever
MarkdownLayoutProps
andMDXLayoutProps
. Can remove if out of scope, but should be useful!Testing
Content
componentfile
andurl
from layoutsDocs
N/A