From 3afa6ec62529fa48a2ca271774303a1afb7e33cc Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Wed, 18 Jan 2023 08:56:39 -0500 Subject: [PATCH 1/7] chore: remove deprecated `getHeaders()` --- packages/astro/src/@types/astro.ts | 2 -- packages/astro/src/vite-plugin-markdown/index.ts | 4 ---- 2 files changed, 6 deletions(-) diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index 75e75f6a3a66..cb972f0f1bfd 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -1028,8 +1028,6 @@ export interface MarkdownInstance> { compiledContent(): string; /** List of headings (h1 -> h6) with associated metadata */ getHeadings(): MarkdownHeading[]; - /** @deprecated Renamed to `getHeadings()` */ - getHeaders(): void; default: AstroComponentFactory; } diff --git a/packages/astro/src/vite-plugin-markdown/index.ts b/packages/astro/src/vite-plugin-markdown/index.ts index 6891bc0d5870..34f155b1a8b8 100644 --- a/packages/astro/src/vite-plugin-markdown/index.ts +++ b/packages/astro/src/vite-plugin-markdown/index.ts @@ -111,10 +111,6 @@ 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; From 44852011f840f7644e7be61731da46d1a6ae40ce Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Wed, 18 Jan 2023 08:58:22 -0500 Subject: [PATCH 2/7] chore: remove `rawContent()` and `compiledContent()` --- packages/integrations/mdx/src/index.ts | 16 ---------------- 1 file changed, 16 deletions(-) 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;', ''); From 6afe0d7b1faba3811d293b79a10346f9b6836e7f Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Wed, 18 Jan 2023 09:00:47 -0500 Subject: [PATCH 3/7] chore: remove raw and compiled content from MDX type --- packages/astro/src/@types/astro.ts | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index cb972f0f1bfd..7b10f3413100 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -1033,13 +1033,7 @@ export interface MarkdownInstance> { 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 interface MDXInstance> extends Omit, 'rawContent' | 'compiledContent'> {}; export interface MarkdownLayoutProps> { frontmatter: { From 12ecd3fc932f65adf47a188cc28a76bd751a3b00 Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Wed, 18 Jan 2023 09:01:00 -0500 Subject: [PATCH 4/7] chore: remove 0.X error for `astro` property --- packages/astro/src/vite-plugin-markdown/index.ts | 16 ---------------- packages/integrations/mdx/src/plugins.ts | 16 ---------------- 2 files changed, 32 deletions(-) diff --git a/packages/astro/src/vite-plugin-markdown/index.ts b/packages/astro/src/vite-plugin-markdown/index.ts index 34f155b1a8b8..746bfde36963 100644 --- a/packages/astro/src/vite-plugin-markdown/index.ts +++ b/packages/astro/src/vite-plugin-markdown/index.ts @@ -115,22 +115,6 @@ export default function markdown({ settings, logging }: AstroPluginOptions): Plu 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/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, From 37c76baac702ddb99a79c582ff78b1666fad5ad0 Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Wed, 18 Jan 2023 09:05:35 -0500 Subject: [PATCH 5/7] chore: changeset --- .changeset/calm-emus-raise.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/calm-emus-raise.md diff --git a/.changeset/calm-emus-raise.md b/.changeset/calm-emus-raise.md new file mode 100644 index 000000000000..d4aa07b4ce9c --- /dev/null +++ b/.changeset/calm-emus-raise.md @@ -0,0 +1,6 @@ +--- +'astro': patch +'@astrojs/mdx': patch +--- + +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. From 3416525cfe23107b665e6b7d2422b5b0bc01b889 Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Wed, 18 Jan 2023 09:15:23 -0500 Subject: [PATCH 6/7] lint: no empty interface --- packages/astro/src/@types/astro.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index 7b10f3413100..b02da1c3a2cd 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -1033,7 +1033,7 @@ export interface MarkdownInstance> { type MD = MarkdownInstance>; -export interface MDXInstance> extends Omit, 'rawContent' | 'compiledContent'> {}; +export type MDXInstance> = Omit, 'rawContent' | 'compiledContent'>; export interface MarkdownLayoutProps> { frontmatter: { From 1a41c2e20869ae9afa1a920b7d9be7c035fbda11 Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Wed, 18 Jan 2023 12:02:30 -0500 Subject: [PATCH 7/7] chore: update changeset --- .changeset/calm-emus-raise.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.changeset/calm-emus-raise.md b/.changeset/calm-emus-raise.md index d4aa07b4ce9c..4e721aecff2d 100644 --- a/.changeset/calm-emus-raise.md +++ b/.changeset/calm-emus-raise.md @@ -1,6 +1,6 @@ --- -'astro': patch -'@astrojs/mdx': patch +'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.