Skip to content

Commit

Permalink
Cleanup deprecated Markdown APIs from 0.X (#5891)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
bholmesdev committed Jan 18, 2023
1 parent 599a05b commit 05caf44
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 61 deletions.
6 changes: 6 additions & 0 deletions .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.
10 changes: 1 addition & 9 deletions packages/astro/src/@types/astro.ts
Expand Up @@ -1028,20 +1028,12 @@ export interface MarkdownInstance<T extends Record<string, any>> {
compiledContent(): string;
/** List of headings (h1 -> h6) with associated metadata */
getHeadings(): MarkdownHeading[];
/** @deprecated Renamed to `getHeadings()` */
getHeaders(): void;
default: AstroComponentFactory;
}

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

export interface MDXInstance<T extends Record<string, any>>
extends Omit<MarkdownInstance<T>, '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<T extends Record<string, any>> = Omit<MarkdownInstance<T>, 'rawContent' | 'compiledContent'>;

export interface MarkdownLayoutProps<T extends Record<string, any>> {
frontmatter: {
Expand Down
20 changes: 0 additions & 20 deletions packages/astro/src/vite-plugin-markdown/index.ts
Expand Up @@ -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
Expand Down
16 changes: 0 additions & 16 deletions packages/integrations/mdx/src/index.ts
Expand Up @@ -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<typeof markdownConfigDefaults, 'remarkPlugins' | 'rehypePlugins'> & {
extendMarkdownConfig: boolean;
recmaPlugins: PluggableList;
Expand Down Expand Up @@ -123,16 +117,6 @@ export default function mdx(partialMdxOptions: Partial<MdxOptions> = {}): 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;', '');
Expand Down
16 changes: 0 additions & 16 deletions packages/integrations/mdx/src/plugins.ts
Expand Up @@ -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,
Expand Down

0 comments on commit 05caf44

Please sign in to comment.