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

[MDX] Fix remaining inconsistencies with Markdown #4268

Merged
merged 18 commits into from
Aug 12, 2022

Conversation

bholmesdev
Copy link
Contributor

@bholmesdev bholmesdev commented Aug 11, 2022

Changes

  • Layout props
    • Add file and url to frontmatter props
  • glob
    • Add <Content /> component export
    • Add rawContent and compiledContent of type never. If called, this will log a helpful error message pointing to new frontmatter injection docs.
  • Types
    • Add *.mdx to declared type module
    • Update glob to use MDXInstance instead. This overrides the rawContent and compiledContent props to be type never
    • Add new MarkdownLayoutProps and MDXLayoutProps. Can remove if out of scope, but should be useful!

Testing

  • test new Content component
  • test file and url from layouts

Docs

N/A

@changeset-bot
Copy link

changeset-bot bot commented Aug 11, 2022

🦋 Changeset detected

Latest commit: bd9ee73

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 14 packages
Name Type
astro Patch
@astrojs/mdx Minor
@e2e/astro-component Patch
@e2e/error-react-spectrum Patch
@e2e/error-sass Patch
@e2e/errors Patch
@e2e/lit-component Patch
@e2e/preact-component Patch
@e2e/react-component Patch
@e2e/solid-component Patch
@e2e/solid-recurse Patch
@e2e/svelte-component Patch
@e2e/e2e-tailwindcss Patch
@e2e/ts-resolution Patch

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

@github-actions github-actions bot added pkg: astro Related to the core `astro` package (scope) pkg: integration Related to any renderer integration (scope) labels Aug 11, 2022
@bholmesdev bholmesdev force-pushed the fix/mdx-md-prop-consistency branch from 7eab1db to c36825e Compare August 12, 2022 15:32
Comment on lines 865 to 875
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'> {}
Copy link
Contributor Author

@bholmesdev bholmesdev Aug 12, 2022

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 }>;
---

Copy link
Member

@natemoo-re natemoo-re left a 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?

packages/astro/src/@types/astro.ts Outdated Show resolved Hide resolved
packages/astro/src/@types/astro.ts Outdated Show resolved Hide resolved
@@ -86,6 +84,8 @@ export default function markdown({ config, logging }: AstroPluginOptions): Plugi
};
export async function Content() {
const { layout, ...content } = frontmatter;
content.file = file;
Copy link
Contributor Author

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.

@bholmesdev bholmesdev merged commit f7afdb8 into main Aug 12, 2022
@bholmesdev bholmesdev deleted the fix/mdx-md-prop-consistency branch August 12, 2022 22:17
@astrobot-houston astrobot-houston mentioned this pull request Aug 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope) pkg: integration Related to any renderer integration (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants