mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 15:47:23 +02:00
refactor: unify how MDX content types are represented (#7145)
* refactor: unify how MDX content types are represented * fix * fix again
This commit is contained in:
parent
b50def3ac0
commit
7a61eed3dd
4 changed files with 25 additions and 33 deletions
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
|
||||
import type {Plugin} from 'unified';
|
||||
import type {TOCItem} from '@docusaurus/types';
|
||||
|
||||
export type MDXPlugin =
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
|
@ -16,3 +17,21 @@ export type MDXOptions = {
|
|||
beforeDefaultRemarkPlugins: MDXPlugin[];
|
||||
beforeDefaultRehypePlugins: MDXPlugin[];
|
||||
};
|
||||
|
||||
export type LoadedMDXContent<FrontMatter, Metadata, Assets = undefined> = {
|
||||
/** As verbatim declared in the MDX document. */
|
||||
readonly frontMatter: FrontMatter;
|
||||
/** As provided by the content plugin. */
|
||||
readonly metadata: Metadata;
|
||||
/** A list of TOC items (headings). */
|
||||
readonly toc: readonly TOCItem[];
|
||||
/** First h1 title before any content. */
|
||||
readonly contentTitle: string | undefined;
|
||||
/**
|
||||
* Usually image assets that may be collocated like `./img/thumbnail.png`.
|
||||
* The loader would also bundle these assets and the client should use these
|
||||
* in priority.
|
||||
*/
|
||||
readonly assets: Assets;
|
||||
(): JSX.Element;
|
||||
};
|
||||
|
|
|
@ -414,7 +414,7 @@ declare module '@docusaurus/plugin-content-blog' {
|
|||
}
|
||||
|
||||
declare module '@theme/BlogPostPage' {
|
||||
import type {TOCItem} from '@docusaurus/types';
|
||||
import type {LoadedMDXContent} from '@docusaurus/mdx-loader';
|
||||
import type {
|
||||
BlogPostFrontMatter,
|
||||
BlogPostMetadata,
|
||||
|
@ -433,22 +433,7 @@ declare module '@theme/BlogPostPage' {
|
|||
}
|
||||
>;
|
||||
|
||||
export type Content = {
|
||||
/** Same as `metadata.frontMatter` */
|
||||
readonly frontMatter: FrontMatter;
|
||||
/**
|
||||
* Usually image assets that may be collocated like `./img/thumbnail.png`.
|
||||
* The loader would also bundle these assets and the client should use these
|
||||
* in priority.
|
||||
*/
|
||||
readonly assets: Assets;
|
||||
/** Metadata of the post. */
|
||||
readonly metadata: Metadata;
|
||||
/** A list of TOC items (headings). */
|
||||
readonly toc: readonly TOCItem[];
|
||||
/** Renders the actual MDX content. */
|
||||
(): JSX.Element;
|
||||
};
|
||||
export type Content = LoadedMDXContent<FrontMatter, Metadata, Assets>;
|
||||
|
||||
export interface Props {
|
||||
/** Blog sidebar. */
|
||||
|
|
|
@ -496,7 +496,7 @@ declare module '@docusaurus/plugin-content-docs' {
|
|||
}
|
||||
|
||||
declare module '@theme/DocItem' {
|
||||
import type {TOCItem} from '@docusaurus/types';
|
||||
import type {LoadedMDXContent} from '@docusaurus/mdx-loader';
|
||||
import type {
|
||||
PropVersionMetadata,
|
||||
Assets,
|
||||
|
@ -514,14 +514,7 @@ declare module '@theme/DocItem' {
|
|||
export interface Props {
|
||||
readonly route: DocumentRoute;
|
||||
readonly versionMetadata: PropVersionMetadata;
|
||||
readonly content: {
|
||||
readonly frontMatter: DocFrontMatter;
|
||||
readonly metadata: DocMetadata;
|
||||
readonly toc: readonly TOCItem[];
|
||||
readonly contentTitle: string | undefined;
|
||||
readonly assets: Assets;
|
||||
(): JSX.Element;
|
||||
};
|
||||
readonly content: LoadedMDXContent<DocFrontMatter, DocMetadata, Assets>;
|
||||
}
|
||||
|
||||
export default function DocItem(props: Props): JSX.Element;
|
||||
|
|
|
@ -48,19 +48,14 @@ declare module '@docusaurus/plugin-content-pages' {
|
|||
}
|
||||
|
||||
declare module '@theme/MDXPage' {
|
||||
import type {TOCItem} from '@docusaurus/types';
|
||||
import type {LoadedMDXContent} from '@docusaurus/mdx-loader';
|
||||
import type {
|
||||
MDXPageMetadata,
|
||||
FrontMatter,
|
||||
} from '@docusaurus/plugin-content-pages';
|
||||
|
||||
export interface Props {
|
||||
readonly content: {
|
||||
readonly frontMatter: FrontMatter;
|
||||
readonly metadata: MDXPageMetadata;
|
||||
readonly toc: readonly TOCItem[];
|
||||
(): JSX.Element;
|
||||
};
|
||||
readonly content: LoadedMDXContent<FrontMatter, MDXPageMetadata>;
|
||||
}
|
||||
|
||||
export default function MDXPage(props: Props): JSX.Element;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue