Create a Page
Add Markdown or React files to src/pages
to create a standalone page:
src/pages/index.js
âlocalhost:3000/
src/pages/foo.md
âlocalhost:3000/foo
src/pages/foo/bar.js
âlocalhost:3000/foo/bar
Create your first React Pageâ
Create a file at src/pages/my-react-page.js
:
import React from "react";
import Layout from "@theme/Layout";
export default function MyReactPage() {
return (
<Layout>
<h1>My React page</h1>
<p>This is a React page</p>
</Layout>
);
}
A new page is now available at http://localhost:3000/my-react-page.
Create your first Markdown Pageâ
Create a file at src/pages/my-markdown-page.md
:
# My Markdown page
This is a Markdown page
A new page is now available at http://localhost:3000/my-markdown-page.
React <Component />
â
MDX allows React components inside Markdown making it more interactive:
export const Highlight = ({children, color}) => (
<span
style={{
backgroundColor: color,
borderRadius: '20px',
color: '#fff',
padding: '10px',
cursor: 'pointer',
}}
onClick={() => {
alert(`You clicked the color ${color} with label ${children}`)
}}>
{children}
</span>
);
This is <Highlight color="#25c2a0">Docusaurus green</Highlight> !
This is <Highlight color="#1877F2">Facebook blue</Highlight> !
This is Docusaurus green !
This is Facebook blue !
Custom Highlightâ
To render the custom highlights:
import React, { type ReactNode } from "react";
export default function Highlight({
children,
color,
}: {
children: ReactNode;
color: string;
}): JSX.Element {
return (
<span
style={{
backgroundColor: color,
borderRadius: "15px",
color: "#fff",
padding: '0.5rem',
}}
>
{children}
</span>
);
}
And some <Highlight color="#1877F2">custom markup</Highlight>
- #1da1f2 <Highlight color="#1da1f2">Primary color</Highlight>
And so on..
-
And some custom markup
-
#1da1f2 Primary color
-
#878787 Secondary color
-
#41B883 Fresh Green
Iconsâ
Font Awesomeâ
Font Awesome Icons. The file MDXComponents.tsx
or MDXComponents.js
should be present in the src/theme
folder.
- npm
- Yarn
- pnpm
npm install --save @fontawesome/fontawesome-svg-core @fontawesome/free-solid-svg-icons @fortawesome/react-fontawesome
yarn add @fontawesome/fontawesome-svg-core @fontawesome/free-solid-svg-icons @fortawesome/react-fontawesome
pnpm add @fontawesome/fontawesome-svg-core @fontawesome/free-solid-svg-icons @fortawesome/react-fontawesome
- npm
- Yarn
- pnpm
npm install --save @fontawesome/free-regular-svg-icons @fontawesome/free-brands-svg-icons
yarn add @fontawesome/free-regular-svg-icons @fontawesome/free-brands-svg-icons
pnpm add @fontawesome/free-regular-svg-icons @fontawesome/free-brands-svg-icons
- JavaScript
- TypeScript
import React from "react";
// Import the original mapper
import MDXComponents from "@theme-original/MDXComponents";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { library } from "@fortawesome/fontawesome-svg-core";
import { fab } from "@fortawesome/free-brands-svg-icons";
import { fas } from "@fortawesome/free-solid-svg-icons";
library.add(fab, fas);
export default {
...MDXComponents,
FAIcon: FontAwesomeIcon, // Make the FontAwesomeIcon component available in MDX as <icon />.
};
import React from "react";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { library } from "@fortawesome/fontawesome-svg-core";
import { fab } from "@fortawesome/free-brands-svg-icons";
import { fas } from "@fortawesome/free-solid-svg-icons";
import MDXComponents from "@theme-original/MDXComponents";
import Code from '@theme/MDXComponents/Code';
library.add(fab, fas);
interface Components {
[key: string]: React.ComponentType<any>;
}
const components: Components = {
...MDXComponents,
FAIcon: FontAwesomeIcon,
Code,
};
export default components;
- JavaScript
- TypeScript
import React from "react";
// Import the original mapper
import MDXComponents from "@theme-original/MDXComponents";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { library } from "@fortawesome/fontawesome-svg-core";
import { fab } from "@fortawesome/free-brands-svg-icons";
import { fas } from "@fortawesome/free-solid-svg-icons";
library.add(fab, fas);
export default {
...MDXComponents,
FAIcon: FontAwesomeIcon, // Make the FontAwesomeIcon component available in MDX as <icon />.
};
import React from "react";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { library } from "@fortawesome/fontawesome-svg-core";
import { fab } from "@fortawesome/free-brands-svg-icons";
import { fas } from "@fortawesome/free-solid-svg-icons";
import MDXComponents from "@theme-original/MDXComponents";
import Code from '@theme/MDXComponents/Code';
library.add(fab, fas);
interface Components {
[key: string]: React.ComponentType<any>;
}
const components: Components = {
...MDXComponents,
FAIcon: FontAwesomeIcon,
Code,
};
export default components;
<FAIcon icon="fa-brands fa-github" size="3x" />
<FAIcon icon="fa-brands fa-x-twitter" size="3x" />
<FAIcon icon="fa-brands fa-youtube" size="3x" />
<FAIcon icon="fa-brands fa-linkedin" size="3x" />
<FAIcon icon="fa-brands fa-python" size="3x" />
<FAIcon icon="fa-brands fa-js" size="3x" />
<FAIcon icon="fa-brands fa-react" size="3x" />
Custom Admonitionsâ
To render these custom admonition in your .mdx
, put import Admonition from "@theme/Admonition";
JSXâ
Use plugins to introduce shorter syntax for the most commonly used JSX elements in your project.
Use plugins to introduce shorter syntax for the most commonly used JSX elements in your project.
Use plugins to introduce shorter syntax for the most commonly used JSX elements in your project.
Use plugins to introduce shorter syntax for the most commonly used JSX elements in your project.
Swizzleâ
Custom tip
This is a security warning
This is a security warning
The quick credit.
Discord
Discord
Release Test
HTML Embedsâ
<pre>
<b>Input: </b>1 2 3 4{'\n'}
<b>Output: </b>"366300745"{'\n'}
</pre>
Input: 1 2 3 4 Output: "366300745"