```
--------------------------------
### Quoted Admonition Example
Source: https://github.com/facebook/docusaurus/blob/main/website/_dogfooding/_docs tests/tests/admonitions.mdx
Illustrates how admonitions can be nested within blockquotes. This example shows a basic admonition within a quote.
```mdx
> :::caution There be dragons
>
> This is the admonition content
>
> :::
>
> > :::caution There be dragons
> >
> > This is the admonition content
> >
> > :::
```
--------------------------------
### Serve Built Docusaurus Website Locally
Source: https://github.com/facebook/docusaurus/blob/main/AGENTS.md
Serves the production-ready built website locally for testing and review.
```bash
pnpm serve:website
```
--------------------------------
### Test Website in Dev/Prod Mode
Source: https://github.com/facebook/docusaurus/blob/main/admin/publish-legacy.md
Navigate to the test-website directory and test the website in development and production modes.
```shell
cd test-website
yarn start
yarn build
yarn serve
```
--------------------------------
### Install Docusaurus Globally
Source: https://github.com/facebook/docusaurus/blob/main/packages/docusaurus-remark-plugin-npm2yarn/src/__tests__/__fixtures__/sync.md
Installs the Docusaurus CLI globally on your system. This command is useful for managing Docusaurus projects across different directories.
```bash
npm install --global docusaurus
```
--------------------------------
### Build Static Website
Source: https://github.com/facebook/docusaurus/blob/main/examples/classic/README.md
Generates the static content for the website into the 'build' directory, ready for hosting.
```bash
yarn build
```
--------------------------------
### Build and Publish Packages with Lerna
Source: https://github.com/facebook/docusaurus/blob/main/admin/publish-legacy.md
Build all necessary packages and then use Lerna to publish a new version. The `--force-publish` and `--exact` flags are important for a clean release.
```sh
yarn build:packages
yarn lerna publish --force-publish --exact 2.0.0-beta.0
```
--------------------------------
### Fortran Hello World Program
Source: https://github.com/facebook/docusaurus/blob/main/website/_dogfooding/_pages tests/code-block-tests.mdx
A Fortran program to print 'Hello, World!', showcasing block and next-line highlighting.
```fortran
! highlight-start
program hello
! highlight-end
implicit none
! highlight-next-line
print *, "Hello, World!"
end program hello
```
--------------------------------
### Install Local Docusaurus Packages with pnpm
Source: https://github.com/facebook/docusaurus/blob/main/admin/local-third-party-project-testing.md
Build and install local Docusaurus packages within the Docusaurus repository itself using pnpm. This step is necessary before linking to an external project.
```bash
cd /path/to/local/docusaurus
pnpm install
```
--------------------------------
### Create a Blog Post
Source: https://github.com/facebook/docusaurus/blob/main/examples/classic/docs/tutorial-basics/create-a-blog-post.mdx
Create a file for your blog post in the `blog/` directory. This markdown file includes front matter for metadata and the post content.
```md
---
slug: greetings
title: Greetings!
authors:
- name: Joel Marcey
title: Co-creator of Docusaurus 1
url: https://github.com/JoelMarcey
image_url: https://github.com/JoelMarcey.png
- name: Sébastien Lorber
title: Docusaurus maintainer
url: https://sebastienlorber.com
image_url: https://github.com/slorber.png
tags: [greetings]
---
Congratulations, you have made your first post!
Feel free to play around and edit this post as much as you like.
```
--------------------------------
### Install npm2yarn Remark Plugin
Source: https://github.com/facebook/docusaurus/blob/main/packages/docusaurus-remark-plugin-npm2yarn/README.md
Install the remark plugin using npm. This is a remark plugin, not a Docusaurus plugin, and needs to be configured within your Docusaurus project's remarkPlugins.
```bash
npm install @docusaurus/remark-plugin-npm2yarn
```
--------------------------------
### IdealImageLegacy Media Component States
Source: https://github.com/facebook/docusaurus/blob/main/packages/docusaurus-plugin-ideal-image/src/theme/IdealImageLegacy/components/MediaWithDefaults/README.md
Demonstrates the MediaWithDefaults component with various 'icon' prop values to represent different states. Includes LQIP placeholder configuration.
```javascript
const lqip =
'data:image/jpeg;base64,/9j/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/2wBDAQcHBwoIChMKChMoGhYaKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wAARCAAIAA4DASIAAhEBAxEB/8QAFgABAQEAAAAAAAAAAAAAAAAAAAUG/8QAIRAAAQQDAAEFAAAAAAAAAAAAAQIDBREABAYhEjEyQVH/xAAUAQEAAAAAAAAAAAAAAAAAAAAE/8QAGBEBAAMBAAAAAAAAAAAAAAAAAQACIRH/2gAMAwEAAhEDEQA/AMJ2DG+7Dw0nz8gsx+uyhlxnWdLakOlfzpIF3aRf1WT5t96P5+N1ug9Tu7ZWS8q1gG6B8H2FDz+YxhjUrEOdZ//Z';
const sqip =
"data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 4774 3024'%3e%3cfilter id='b'%3e%3cfeGaussianBlur stdDeviation='12' /%3e%3c/filter%3e%3cpath fill='%23515a57' d='M0 0h4774v3021H0z'/%3e%3cg filter='url(%23b)' transform='translate(9.3 9.3) scale(18.64844)' fill-opacity='.5'%3e%3cellipse fill='whitefef' rx='1' ry='1' transform='matrix(74.55002 60.89891 -21.7939 26.67923 151.8 104.4)'/%3e%3cellipse fill='black80c' cx='216' cy='49' rx='59' ry='59'/%3e%3cellipse fill='black60e' cx='22' cy='60' rx='46' ry='89'/%3e%3cellipse fill='%23ffebd5' cx='110' cy='66' rx='42' ry='28'/%3e%3cellipse fill='whiteff9' rx='1' ry='1' transform='rotate(33.3 -113.2 392.6) scale(42.337 17.49703)'/%3e%3cellipse fill='%23031f1e' rx='1' ry='1' transform='matrix(163.4651 -64.93326 6.77862 17.06471 111 16.4)'/%3e%3cpath fill='whitefea' d='M66 74l9 39 16-44z'/%3e%3cellipse fill='%23a28364' rx='1' ry='1' transform='rotate(-32.4 253.2 -179) scale(30.79511 43.65381)'/%3e%3cpath fill='%231a232c' d='M40 139l61-57 33 95z'/%3e%3cpath fill='%230a222b' d='M249.8 153.3l-48.1-48 32.5-32.6 48.1 48z'/%3e%3c/g%3e%3c/svg%3e";
|
load
|
|
noicon
|
|
| loading |
|
offline |
|
| loaded |
|
error |
|
;
```
--------------------------------
### Live React Clock Example
Source: https://github.com/facebook/docusaurus/blob/main/packages/docusaurus-theme-live-codeblock/README.md
A functional React component demonstrating a live updating clock within a Docusaurus page. This example requires React's useState and useEffect hooks.
```jsx
function Clock(props) {
const [date, setDate] = useState(new Date());
useEffect(() => {
var timerID = setInterval(() => tick(), 1000);
return function cleanup() {
clearInterval(timerID);
};
});
function tick() {
setDate(new Date());
}
return (
It is {date.toLocaleTimeString()}.
);
}
```
--------------------------------
### Import README as MDX
Source: https://github.com/facebook/docusaurus/blob/main/website/_dogfooding/_pages tests/index.mdx
Shows how to import a README file (assuming it's an MDX file) into an MDX page.
```mdx
import Readme from "../README.mdx"
```
--------------------------------
### Install Docusaurus from Verdaccio Local Registry
Source: https://github.com/facebook/docusaurus/blob/main/admin/local-third-party-project-testing.md
Install a specific version of Docusaurus from a local Verdaccio registry. Ensure the Verdaccio service is running and the version number reflects the latest published local version.
```bash
pnpm_config_registry="http://localhost:4873" pnpm install @docusaurus/core@"2.0.0-beta.8.NEW"
```
--------------------------------
### Initialize docusaurus project
Source: https://github.com/facebook/docusaurus/blob/main/packages/docusaurus-remark-plugin-npm2yarn/src/__tests__/__fixtures__/conversion-test.md
Converts npm commands for initializing a docusaurus project to their yarn equivalents.
```bash
npm init docusaurus
```
```bash
yarn create docusaurus
```
```bash
npm init docusaurus@latest my-website classic
```
```bash
yarn create docusaurus@latest my-website classic
```
--------------------------------
### Import MDX Partial
Source: https://github.com/facebook/docusaurus/blob/main/website/_dogfooding/_pages tests/index.mdx
Demonstrates how to import and render an MDX partial component within another MDX file.
```mdx
import PagePartial from "./_pagePartial.mdx"
```
--------------------------------
### Mermaid Mindmap diagram
Source: https://github.com/facebook/docusaurus/blob/main/website/blog/releases/3.0/index.mdx
Example of a mindmap diagram rendered using Mermaid syntax.
```mermaid
mindmap
root((mindmap))
Research
Creative techniques
Strategic planning
Argument mapping
Tools
Pen and paper
Mermaid
```
--------------------------------
### Another Basic Text Directive
Source: https://github.com/facebook/docusaurus/blob/main/packages/docusaurus-mdx-loader/src/remark/unusedDirectives/__tests__/__fixtures__/textDirectives.md
A standalone text directive, similar to the first example.
```markdown
Simple:textDirective5
```
--------------------------------
### Minimal GitHub Actions Workflow for Argos CI
Source: https://github.com/facebook/docusaurus/blob/main/website/blog/2023/09-22-upgrading-frontend-dependencies-with-confidence-using-visual-regression-testing/index.mdx
This YAML configuration sets up a GitHub Actions workflow that runs on push to main and pull requests targeting main. It checks out code, sets up Node.js, installs dependencies, installs Playwright browsers, builds the Docusaurus site, takes screenshots using Playwright, and uploads them to Argos.
```yaml
name: Argos CI Screenshots
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
take-screenshots:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: current
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Install Playwright browsers
run: yarn playwright install --with-deps chromium
- name: Build the website
run: yarn docusaurus build
- name: Take screenshots with Playwright
run: yarn playwright test
- name: Upload screenshots to Argos
run: yarn argos upload ./screenshots
```
--------------------------------
### Add Metadata to Markdown Files
Source: https://github.com/facebook/docusaurus/blob/main/website/blog/2018/04-30-How-I-Converted-Profilo-To-Docusaurus.mdx
Example of metadata to be added to Markdown files for Docusaurus documentation.
```markdown
---
id: architecture
title: Architecture
sidebar_label: Architecture
---
```
--------------------------------
### Admonition Alias Example
Source: https://github.com/facebook/docusaurus/blob/main/website/_dogfooding/_pages tests/markdown-tests-mdx.mdx
Illustrates using an admonition alias like 'important' which defaults to an 'Important' title.
```mdx
:::important
Admonition alias `:::important` should have Important title
:::
```
--------------------------------
### Using require for Site-Level Image Source
Source: https://github.com/facebook/docusaurus/blob/main/website/_dogfooding/_blog tests/2021-10-08-blog-post-mdx-require-feed-tests.mdx
Illustrates using `require` with an alias (`@site`) to reference an image file located at the site level.
```javascript
```
--------------------------------
### Exporting a Constant
Source: https://github.com/facebook/docusaurus/blob/main/packages/docusaurus-mdx-loader/src/remark/toc/__tests__/__fixtures__/just-content.md
This snippet shows a simple JavaScript export statement. It is a basic example of module export.
```javascript
export const c = 1;
```
--------------------------------
### Build Your Docusaurus Site for Production
Source: https://github.com/facebook/docusaurus/blob/main/examples/classic/docs/tutorial-basics/deploy-your-site.mdx
Run this command to generate static HTML, JavaScript, and CSS files for your Docusaurus site. The output is placed in the `build` folder.
```bash
npm run build
```
--------------------------------
### Indented Admonition Example
Source: https://github.com/facebook/docusaurus/blob/main/website/_dogfooding/_docs tests/tests/admonitions.mdx
Demonstrates how admonitions can be indented within lists or other block elements. This syntax is compatible with v2.
```mdx
:::info Important Considerations
For better experience, try to keep the upgrade experience smooth.
:::
:::caution Warning
Scaling up a cluster may cause several minutes of downtime. Please exercise caution.
:::
```
--------------------------------
### Create a React Page
Source: https://github.com/facebook/docusaurus/blob/main/examples/classic/docs/tutorial-basics/create-a-page.mdx
Create a React component file in `src/pages` to generate a new page. The component should return JSX wrapped in a Docusaurus `Layout` component.
```jsx
import React from 'react';
import Layout from '@theme/Layout';
export default function MyReactPage() {
return (
My React page
This is a React page
);
}
```
--------------------------------
### VB.NET HashSet Initialization
Source: https://github.com/facebook/docusaurus/blob/main/website/_dogfooding/_pages tests/code-block-tests.mdx
VB.NET code to initialize a HashSet with string values, demonstrating next-line and block highlighting.
```vbnet
' highlight-next-line
Dim languages As New HashSet(Of String) From {
"C#",
"Visual Basic",
_ ' highlight-start
"F#",
"PowerShell",
"TypeScript"
_' highlight-end
}
```
--------------------------------
### Mermaid Architecture Diagram
Source: https://github.com/facebook/docusaurus/blob/main/website/_dogfooding/_pages tests/diagrams.mdx
Example of an architecture diagram using Mermaid syntax. Ensure Mermaid is enabled in your Docusaurus configuration.
```mermaid
architecture-beta
group api(cloud)[API]
service db(database)[Database] in api
service disk1(disk)[Storage] in api
service disk2(disk)[Storage] in api
service server(server)[Server] in api
db:L -- R:server
disk1:T -- B:server
disk2:T -- B:db
```
--------------------------------
### Markdown Heading ID Example
Source: https://github.com/facebook/docusaurus/blob/main/examples/classic/docs/tutorial-basics/markdown-features.mdx
Assigns an explicit anchor ID to a Markdown heading by appending `{/* #my-custom-id */}` after the heading text.
```md
### Heading Ids {/_ #my-custom-id _/}
```
--------------------------------
### Create a Basic Markdown Document
Source: https://github.com/facebook/docusaurus/blob/main/examples/classic/docs/tutorial-basics/create-a-document.mdx
Create a simple Markdown file in the `docs` folder. This file will be automatically rendered as a document on your site.
```markdown
# Hello
This is my **first Docusaurus document**!
```
--------------------------------
### Generate Changelog with Specific Version
Source: https://github.com/facebook/docusaurus/blob/main/admin/publish-legacy.md
Generates the changelog starting from a specific version, which can help resolve issues with empty changelogs.
```bash
yarn changelog --from v2.0.0-beta.0
```
--------------------------------
### Browser Window Component Usage
Source: https://github.com/facebook/docusaurus/blob/main/website/_dogfooding/_pages tests/markdown-tests-md.md
Demonstrates the usage of a custom BrowserWindow component.
```jsx
import BrowserWindow from '@site/src/components/BrowserWindow';
BrowserWindow content
```
--------------------------------
### Generate a New Docusaurus Site
Source: https://github.com/facebook/docusaurus/blob/main/examples/classic/docs/intro.mdx
Use this command to create a new Docusaurus site with the classic template. It installs all necessary dependencies.
```bash
npm init docusaurus@latest my-website classic
```
--------------------------------
### Using require for Local Image Source
Source: https://github.com/facebook/docusaurus/blob/main/website/_dogfooding/_blog tests/2021-10-08-blog-post-mdx-require-feed-tests.mdx
Shows how to use a `require` call to reference a local image file, accessing its default export.
```javascript
```
--------------------------------
### Fast Production Build for Docusaurus Website
Source: https://github.com/facebook/docusaurus/blob/main/AGENTS.md
Builds the Docusaurus website for production, focusing on recent versions to speed up the build time and feedback loop.
```bash
pnpm build:website:fast
```
--------------------------------
### Import SVG as React Component
Source: https://github.com/facebook/docusaurus/blob/main/website/blog/releases/3.7/index.mdx
Use SVGs directly as React components in your Docusaurus site. This example shows a basic import.
```tsx
import DocusaurusSvg from './docusaurus.svg';
;
```
--------------------------------
### Docusaurus v2 Warning Admonition
Source: https://github.com/facebook/docusaurus/blob/main/website/blog/2023/09-29-preparing-your-site-for-docusaurus-v3/index.mdx
Example of the undocumented `:::warning` admonition in Docusaurus v2, which renders with a red color and incorrect icon.
```markdown
:::danger Warning
This is a Docusaurus v2 `:::warning` admonition.
:::
```
--------------------------------
### JavaScript Clock Component with Highlighting
Source: https://github.com/facebook/docusaurus/blob/main/website/_dogfooding/_pages tests/markdown-tests-md.md
A JavaScript React component for a ticking clock, featuring code highlighting and long line examples.
```javascript
function Clock(props) {
const [date, setDate] = useState(new Date());
useEffect(() => {
var timerID = setInterval(() => tick(), 1000);
return function cleanup() {
clearInterval(timerID);
};
});
function tick() {
setDate(new Date());
}
return (
It is {date.toLocaleTimeString()}.
// highlight-start
{/* prettier-ignore */}
long long long long long long long long long long long long line
{/* prettier-ignore */}
// highlight-end
);
}
```
--------------------------------
### Import and Render Partial Component
Source: https://github.com/facebook/docusaurus/blob/main/website/_dogfooding/_blog tests/2021-08-22-no-author.mdx
This snippet demonstrates how to import and render a partial MDX component within a Docusaurus blog post. Ensure the partial component exists at the specified path.
```mdx
import Partial from "./_partial.mdx"
```