diff --git a/.changeset/calm-emus-raise.md b/.changeset/calm-emus-raise.md new file mode 100644 index 000000000000..4e721aecff2d --- /dev/null +++ b/.changeset/calm-emus-raise.md @@ -0,0 +1,6 @@ +--- +'astro': major +'@astrojs/mdx': minor +--- + +Remove deprecated Markdown APIs from Astro v0.X. This includes `getHeaders()`, the `.astro` property for layouts, and the `rawContent()` and `compiledContent()` error messages for MDX. diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index 75e75f6a3a66..b02da1c3a2cd 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -1028,20 +1028,12 @@ export interface MarkdownInstance> { compiledContent(): string; /** List of headings (h1 -> h6) with associated metadata */ getHeadings(): MarkdownHeading[]; - /** @deprecated Renamed to `getHeadings()` */ - getHeaders(): void; default: AstroComponentFactory; } type MD = MarkdownInstance>; -export interface MDXInstance> - extends Omit, 'rawContent' | 'compiledContent'> { - /** MDX does not support rawContent! If you need to read the Markdown contents to calculate values (ex. reading time), we suggest injecting frontmatter via remark plugins. Learn more on our docs: https://docs.astro.build/en/guides/integrations-guide/mdx/#inject-frontmatter-via-remark-or-rehype-plugins */ - rawContent: never; - /** MDX does not support compiledContent! If you need to read the HTML contents to calculate values (ex. reading time), we suggest injecting frontmatter via rehype plugins. Learn more on our docs: https://docs.astro.build/en/guides/integrations-guide/mdx/#inject-frontmatter-via-remark-or-rehype-plugins */ - compiledContent: never; -} +export type MDXInstance> = Omit, 'rawContent' | 'compiledContent'>; export interface MarkdownLayoutProps> { frontmatter: { diff --git a/packages/astro/src/vite-plugin-markdown/index.ts b/packages/astro/src/vite-plugin-markdown/index.ts index 6891bc0d5870..746bfde36963 100644 --- a/packages/astro/src/vite-plugin-markdown/index.ts +++ b/packages/astro/src/vite-plugin-markdown/index.ts @@ -111,30 +111,10 @@ export default function markdown({ settings, logging }: AstroPluginOptions): Plu export function getHeadings() { return ${JSON.stringify(headings)}; } - export function getHeaders() { - console.warn('getHeaders() have been deprecated. Use getHeadings() function instead.'); - return getHeadings(); - }; export async function Content() { const { layout, ...content } = frontmatter; content.file = file; content.url = url; - content.astro = {}; - Object.defineProperty(content.astro, 'headings', { - get() { - throw new Error('The "astro" property is no longer supported! To access "headings" from your layout, try using "Astro.props.headings."') - } - }); - Object.defineProperty(content.astro, 'html', { - get() { - throw new Error('The "astro" property is no longer supported! To access "html" from your layout, try using "Astro.props.compiledContent()."') - } - }); - Object.defineProperty(content.astro, 'source', { - get() { - throw new Error('The "astro" property is no longer supported! To access "source" from your layout, try using "Astro.props.rawContent()."') - } - }); const contentFragment = h(Fragment, { 'set:html': html }); return ${ layout diff --git a/packages/integrations/mdx/src/index.ts b/packages/integrations/mdx/src/index.ts index 756e6d24f23b..577d073ee19b 100644 --- a/packages/integrations/mdx/src/index.ts +++ b/packages/integrations/mdx/src/index.ts @@ -12,12 +12,6 @@ import type { Plugin as VitePlugin } from 'vite'; import { getRehypePlugins, getRemarkPlugins, recmaInjectImportMetaEnvPlugin } from './plugins.js'; import { getFileInfo, parseFrontmatter } from './utils.js'; -const RAW_CONTENT_ERROR = - 'MDX does not support rawContent()! If you need to read the Markdown contents to calculate values (ex. reading time), we suggest injecting frontmatter via remark plugins. Learn more on our docs: https://docs.astro.build/en/guides/integrations-guide/mdx/#inject-frontmatter-via-remark-or-rehype-plugins'; - -const COMPILED_CONTENT_ERROR = - 'MDX does not support compiledContent()! If you need to read the HTML contents to calculate values (ex. reading time), we suggest injecting frontmatter via rehype plugins. Learn more on our docs: https://docs.astro.build/en/guides/integrations-guide/mdx/#inject-frontmatter-via-remark-or-rehype-plugins'; - export type MdxOptions = Omit & { extendMarkdownConfig: boolean; recmaPlugins: PluggableList; @@ -123,16 +117,6 @@ export default function mdx(partialMdxOptions: Partial = {}): AstroI if (!moduleExports.includes('file')) { code += `\nexport const file = ${JSON.stringify(fileId)};`; } - if (!moduleExports.includes('rawContent')) { - code += `\nexport function rawContent() { throw new Error(${JSON.stringify( - RAW_CONTENT_ERROR - )}) };`; - } - if (!moduleExports.includes('compiledContent')) { - code += `\nexport function compiledContent() { throw new Error(${JSON.stringify( - COMPILED_CONTENT_ERROR - )}) };`; - } if (!moduleExports.includes('Content')) { // Make `Content` the default export so we can wrap `MDXContent` and pass in `Fragment` code = code.replace('export default MDXContent;', ''); diff --git a/packages/integrations/mdx/src/plugins.ts b/packages/integrations/mdx/src/plugins.ts index 6b97bc77cce0..8c98e0016e97 100644 --- a/packages/integrations/mdx/src/plugins.ts +++ b/packages/integrations/mdx/src/plugins.ts @@ -79,22 +79,6 @@ export function rehypeApplyFrontmatterExport() { const { layout, ...content } = frontmatter; content.file = file; content.url = url; - content.astro = {}; - Object.defineProperty(content.astro, 'headings', { - get() { - throw new Error('The "astro" property is no longer supported! To access "headings" from your layout, try using "Astro.props.headings."') - } - }); - Object.defineProperty(content.astro, 'html', { - get() { - throw new Error('The "astro" property is no longer supported! To access "html" from your layout, try using "Astro.props.compiledContent()."') - } - }); - Object.defineProperty(content.astro, 'source', { - get() { - throw new Error('The "astro" property is no longer supported! To access "source" from your layout, try using "Astro.props.rawContent()."') - } - }); return layoutJsx(Layout, { file, url,