Using MDX in Frosti
Sat Dec 07 2024
627 words · 4 minutes

Using MDX in Frosti


Table of Contents

This article describes how to use the custom components provided by Frosti in .mdx files to create rich content that standard Markdown can’t support.

Getting Started Link to Getting Started

To use these components, simply create a file with the .mdx extension. Frosti has built-in support for MDX.

Importing Components Link to Importing Components

The components provided by Frosti are located in the /src/components/mdx/ directory. You need to import them in the frontmatter section of your MDX file:

MDX
1
2
3
4
5
6
7
8
9
import Collapse from "../../components/mdx/Collapse.astro";
import Diff from "../../components/mdx/Diff.astro";
import Error from "../../components/mdx/Error.astro";
import Info from "../../components/mdx/Info.astro";
import Kbd from "../../components/mdx/Kbd.astro";
import Success from "../../components/mdx/Success.astro";
import Warning from "../../components/mdx/Warning.astro";
import TimeLine from "../../components/mdx/TimeLine.astro";
import LinkCard from "../../components/mdx/LinkCard.astro";

Component Examples Link to Component Examples

Below are examples of how to use each component.

Collapse (Accordion) Link to Collapse (Accordion)

Use <Collapse> to hide content that can be toggled by the user.

Click to reveal hidden content

This is the hidden content! You can put text, code, or other components here.

Code:

MDX
1
2
3
<Collapse title="Click to reveal hidden content">
  This is the hidden content! You can put text, code, or other components here.
</Collapse>

Diff (Image Comparison) Link to Diff (Image Comparison)

Use <Diff> to compare two images side-by-side with a slider.

Left image
Right image

Code:

MDX
1
<Diff r="/image/r.png" l="/image/l.png" />

Alert Boxes Link to Alert Boxes

Use these components to highlight important information.

Error Link to Error

MDX
1
<Error>Something went wrong! Please check your configuration.</Error>

Warning Link to Warning

MDX
1
<Warning>Proceed with caution. This action cannot be undone.</Warning>

Info Link to Info

MDX
1
<Info>Here is some useful information for you.</Info>

Success Link to Success

MDX
1
<Success>Operation completed successfully!</Success>

Kbd (Keyboard Input) Link to Kbd (Keyboard Input)

Use <Kbd> to represent keyboard keys.

Press Ctrl + C to copy.

Code:

MDX
1
Press <Kbd>Ctrl</Kbd> + <Kbd>C</Kbd> to copy.

TimeLine Link to TimeLine

Use <TimeLine> to display a sequence of events.

  • First Macintosh computer



  • iMac



  • iPod



  • iPhone



  • Apple Watch


Code:

MDX
1
2
3
4
5
6
7
8
9
<TimeLine
  items={[
    { year: "1984", event: "First Macintosh computer" },
    { year: "1998", event: "iMac" },
    { year: "2001", event: "iPod" },
    { year: "2007", event: "iPhone" },
    { year: "2015", event: "Apple Watch" },
  ]}
/>

LinkCard Link to LinkCard

Use <LinkCard> to display a rich link preview.

Code:

MDX
1
2
3
4
5
6
<LinkCard
  title="Frosti"
  desc="A clean and feature-rich Astro blog theme."
  url="https://github.com/EveSunMaple/Frosti"
  img="/view.png"
/>

Common Pitfalls Link to Common Pitfalls

References Link to References

Thanks for reading!

Using MDX in Frosti

Sat Dec 07 2024
627 words · 4 minutes