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
This commit is contained in:
Ben Holmes 2023-01-18 17:04:37 -05:00 committed by GitHub
parent 599a05bfb5
commit 05caf445d4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 7 additions and 61 deletions

View file

@ -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.

View file

@ -1028,20 +1028,12 @@ export interface MarkdownInstance<T extends Record<string, any>> {
compiledContent(): string; compiledContent(): string;
/** List of headings (h1 -> h6) with associated metadata */ /** List of headings (h1 -> h6) with associated metadata */
getHeadings(): MarkdownHeading[]; getHeadings(): MarkdownHeading[];
/** @deprecated Renamed to `getHeadings()` */
getHeaders(): void;
default: AstroComponentFactory; default: AstroComponentFactory;
} }
type MD = MarkdownInstance<Record<string, any>>; type MD = MarkdownInstance<Record<string, any>>;
export interface MDXInstance<T extends Record<string, any>> export type MDXInstance<T extends Record<string, any>> = Omit<MarkdownInstance<T>, 'rawContent' | 'compiledContent'>;
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 interface MarkdownLayoutProps<T extends Record<string, any>> { export interface MarkdownLayoutProps<T extends Record<string, any>> {
frontmatter: { frontmatter: {

View file

@ -111,30 +111,10 @@ export default function markdown({ settings, logging }: AstroPluginOptions): Plu
export function getHeadings() { export function getHeadings() {
return ${JSON.stringify(headings)}; return ${JSON.stringify(headings)};
} }
export function getHeaders() {
console.warn('getHeaders() have been deprecated. Use getHeadings() function instead.');
return getHeadings();
};
export async function Content() { export async function Content() {
const { layout, ...content } = frontmatter; const { layout, ...content } = frontmatter;
content.file = file; content.file = file;
content.url = url; 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 }); const contentFragment = h(Fragment, { 'set:html': html });
return ${ return ${
layout layout

View file

@ -12,12 +12,6 @@ import type { Plugin as VitePlugin } from 'vite';
import { getRehypePlugins, getRemarkPlugins, recmaInjectImportMetaEnvPlugin } from './plugins.js'; import { getRehypePlugins, getRemarkPlugins, recmaInjectImportMetaEnvPlugin } from './plugins.js';
import { getFileInfo, parseFrontmatter } from './utils.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'> & { export type MdxOptions = Omit<typeof markdownConfigDefaults, 'remarkPlugins' | 'rehypePlugins'> & {
extendMarkdownConfig: boolean; extendMarkdownConfig: boolean;
recmaPlugins: PluggableList; recmaPlugins: PluggableList;
@ -123,16 +117,6 @@ export default function mdx(partialMdxOptions: Partial<MdxOptions> = {}): AstroI
if (!moduleExports.includes('file')) { if (!moduleExports.includes('file')) {
code += `\nexport const file = ${JSON.stringify(fileId)};`; 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')) { if (!moduleExports.includes('Content')) {
// Make `Content` the default export so we can wrap `MDXContent` and pass in `Fragment` // Make `Content` the default export so we can wrap `MDXContent` and pass in `Fragment`
code = code.replace('export default MDXContent;', ''); code = code.replace('export default MDXContent;', '');

View file

@ -79,22 +79,6 @@ export function rehypeApplyFrontmatterExport() {
const { layout, ...content } = frontmatter; const { layout, ...content } = frontmatter;
content.file = file; content.file = file;
content.url = url; 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, { return layoutJsx(Layout, {
file, file,
url, url,