Skip to content

Commit 05caf44

Browse files
authored
Cleanup deprecated Markdown APIs from 0.X (#5891)
* chore: remove deprecated `getHeaders()` * chore: remove `rawContent()` and `compiledContent()` * chore: remove raw and compiled content from MDX type * chore: remove 0.X error for `astro` property * chore: changeset * lint: no empty interface * chore: update changeset
1 parent 599a05b commit 05caf44

5 files changed

Lines changed: 7 additions & 61 deletions

File tree

.changeset/calm-emus-raise.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'astro': major
3+
'@astrojs/mdx': minor
4+
---
5+
6+
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.

packages/astro/src/@types/astro.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,20 +1028,12 @@ export interface MarkdownInstance<T extends Record<string, any>> {
10281028
compiledContent(): string;
10291029
/** List of headings (h1 -> h6) with associated metadata */
10301030
getHeadings(): MarkdownHeading[];
1031-
/** @deprecated Renamed to `getHeadings()` */
1032-
getHeaders(): void;
10331031
default: AstroComponentFactory;
10341032
}
10351033

10361034
type MD = MarkdownInstance<Record<string, any>>;
10371035

1038-
export interface MDXInstance<T extends Record<string, any>>
1039-
extends Omit<MarkdownInstance<T>, 'rawContent' | 'compiledContent'> {
1040-
/** 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 */
1041-
rawContent: never;
1042-
/** 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 */
1043-
compiledContent: never;
1044-
}
1036+
export type MDXInstance<T extends Record<string, any>> = Omit<MarkdownInstance<T>, 'rawContent' | 'compiledContent'>;
10451037

10461038
export interface MarkdownLayoutProps<T extends Record<string, any>> {
10471039
frontmatter: {

packages/astro/src/vite-plugin-markdown/index.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -111,30 +111,10 @@ export default function markdown({ settings, logging }: AstroPluginOptions): Plu
111111
export function getHeadings() {
112112
return ${JSON.stringify(headings)};
113113
}
114-
export function getHeaders() {
115-
console.warn('getHeaders() have been deprecated. Use getHeadings() function instead.');
116-
return getHeadings();
117-
};
118114
export async function Content() {
119115
const { layout, ...content } = frontmatter;
120116
content.file = file;
121117
content.url = url;
122-
content.astro = {};
123-
Object.defineProperty(content.astro, 'headings', {
124-
get() {
125-
throw new Error('The "astro" property is no longer supported! To access "headings" from your layout, try using "Astro.props.headings."')
126-
}
127-
});
128-
Object.defineProperty(content.astro, 'html', {
129-
get() {
130-
throw new Error('The "astro" property is no longer supported! To access "html" from your layout, try using "Astro.props.compiledContent()."')
131-
}
132-
});
133-
Object.defineProperty(content.astro, 'source', {
134-
get() {
135-
throw new Error('The "astro" property is no longer supported! To access "source" from your layout, try using "Astro.props.rawContent()."')
136-
}
137-
});
138118
const contentFragment = h(Fragment, { 'set:html': html });
139119
return ${
140120
layout

packages/integrations/mdx/src/index.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@ import type { Plugin as VitePlugin } from 'vite';
1212
import { getRehypePlugins, getRemarkPlugins, recmaInjectImportMetaEnvPlugin } from './plugins.js';
1313
import { getFileInfo, parseFrontmatter } from './utils.js';
1414

15-
const RAW_CONTENT_ERROR =
16-
'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';
17-
18-
const COMPILED_CONTENT_ERROR =
19-
'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';
20-
2115
export type MdxOptions = Omit<typeof markdownConfigDefaults, 'remarkPlugins' | 'rehypePlugins'> & {
2216
extendMarkdownConfig: boolean;
2317
recmaPlugins: PluggableList;
@@ -123,16 +117,6 @@ export default function mdx(partialMdxOptions: Partial<MdxOptions> = {}): AstroI
123117
if (!moduleExports.includes('file')) {
124118
code += `\nexport const file = ${JSON.stringify(fileId)};`;
125119
}
126-
if (!moduleExports.includes('rawContent')) {
127-
code += `\nexport function rawContent() { throw new Error(${JSON.stringify(
128-
RAW_CONTENT_ERROR
129-
)}) };`;
130-
}
131-
if (!moduleExports.includes('compiledContent')) {
132-
code += `\nexport function compiledContent() { throw new Error(${JSON.stringify(
133-
COMPILED_CONTENT_ERROR
134-
)}) };`;
135-
}
136120
if (!moduleExports.includes('Content')) {
137121
// Make `Content` the default export so we can wrap `MDXContent` and pass in `Fragment`
138122
code = code.replace('export default MDXContent;', '');

packages/integrations/mdx/src/plugins.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,22 +79,6 @@ export function rehypeApplyFrontmatterExport() {
7979
const { layout, ...content } = frontmatter;
8080
content.file = file;
8181
content.url = url;
82-
content.astro = {};
83-
Object.defineProperty(content.astro, 'headings', {
84-
get() {
85-
throw new Error('The "astro" property is no longer supported! To access "headings" from your layout, try using "Astro.props.headings."')
86-
}
87-
});
88-
Object.defineProperty(content.astro, 'html', {
89-
get() {
90-
throw new Error('The "astro" property is no longer supported! To access "html" from your layout, try using "Astro.props.compiledContent()."')
91-
}
92-
});
93-
Object.defineProperty(content.astro, 'source', {
94-
get() {
95-
throw new Error('The "astro" property is no longer supported! To access "source" from your layout, try using "Astro.props.rawContent()."')
96-
}
97-
});
9882
return layoutJsx(Layout, {
9983
file,
10084
url,

0 commit comments

Comments
 (0)