This document is a guide on how to set up the template and use MDX with Astro.
-
Fork the repository. In the top-right corner of the page, click the Fork button. Adjust your settings then create fork.
-
Clone your forked repository:
git clone https://github.com/jrgo7/your-forked-repository
- Install the dependencies:
npm install
- Run the dev server:
npm run dev
├── astro.config.mjs
├── package.json
├── package-lock.json
├── tsconfig.json
└── src/
├── components/
│ ├── ReactComponent.jsx
│ └── AstroComponent.astro
├── layouts/
│ └── ExhibitLayout.astro
└── pages/
└── topic_name.mdx
| Path | Description |
|---|---|
src/pages/ |
Place your .mdx files here. Astro creates automatic routing from filenames. |
src/components/ |
Your custom React/Astro components. |
src/layouts/ExhibitLayout.astro |
Shared layout to be used. Don't restructure it. |
astro.config.mjs |
Already configured. Only modify if adding new integrations. |
- Create a
.mdxfile insidesrc/pages/named after your topic (e.g.heartbleed-bug.mdx). - Add frontmatter at the top of the file.
- Write your content in Markdown and import components as needed.
Add this at the very top of your .mdx file before any content:
---
layout: ../layouts/ExhibitLayout.astro
title: "Your Title Here"
description: "A short description of your topic."
author: "Surname, Firstname; Surname2, Firstname2"
readingTime: "67 minutes"
---The frontmatter block is not rendered as content. Astro reads it to know which layout to use and what to put in the page's metadata.
Astro components (.astro) are ideal for static content like section wrappers, info cards, and image galleries.
Create src/components/InfoCard.astro:
---
const { title, body } = Astro.props;
---
<div class="info-card">
<h3>{title}</h3>
<p>{body}</p>
</div>
<style>
.info-card {
border: 1px solid var(--border-color);
padding: 1rem;
border-radius: 8px;
}
</style>Then use it in your .mdx:
import InfoCard from '../components/InfoCard.astro';
<InfoCard title="What is a buffer over-read?" body="It occurs when a program reads more data than was intended from a buffer." />React components (.jsx or .tsx) are used for interactive elements like quizzes, simulations, and timelines. They run in the browser.
- Create your component in
src/components/with a default export:
// src/components/MyComponent.jsx
export default function MyComponent() {
return <div>Hello from React!</div>;
}- Import and use it in your
.mdx:
import MyComponent from '../components/MyComponent.jsx';
<MyComponent client:load />Note on
client:directives: By default, Astro renders React components as static HTML. Add aclient:directive to make them interactive in the browser.
Directive When it hydrates client:loadImmediately on page load client:visibleWhen the component scrolls into view client:idleWhen the browser is idle
- Astro is a modern web framework designed for building fast, content-focused websites.
- Astro defaults to zero client-side JavaScript, making pages render faster.
- Astro also supports multiple frameworks at once.
- For more information: https://docs.astro.build/en/getting-started/
- MDX is a Markdown + JSX tool that lets you add interactive elements to your Markdown pages.
- You can import components, create charts and diagrams, and build interactive elements using Markdown.
- For more information: https://mdxjs.com/docs/
Place your .mdx files inside src/pages/. Astro will handle routing automatically.
└── src/
└── pages/
└── topic_name.mdx <--- your exhibit page
Astro handles routing automatically once your .mdx file is in src/pages/.
- Run the server:
npm run dev
- Visit your page at
localhost:4321/virtual-exhibit-template/topic_name.