Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v4] make compileMdx from nextra/compile return a string instead of an object #3694

Merged
merged 40 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
d676456
aa
dimaMachina Nov 10, 2024
2888b80
more
dimaMachina Nov 10, 2024
08a8328
more
dimaMachina Nov 10, 2024
ebda5c1
more
dimaMachina Nov 10, 2024
32ba635
more
dimaMachina Nov 10, 2024
4d51b6f
more
dimaMachina Nov 10, 2024
cb75b88
more
dimaMachina Nov 10, 2024
07f4159
more
dimaMachina Nov 10, 2024
fd98602
more
dimaMachina Nov 10, 2024
8a8da29
more
dimaMachina Nov 10, 2024
98c1c0d
more
dimaMachina Nov 10, 2024
31ee324
more
dimaMachina Nov 11, 2024
c3b94c6
more
dimaMachina Nov 11, 2024
a8db331
more
dimaMachina Nov 11, 2024
7fa1d39
moree
dimaMachina Nov 11, 2024
e43841b
moree
dimaMachina Nov 11, 2024
ebb7725
moree
dimaMachina Nov 11, 2024
4c71e7e
moree
dimaMachina Nov 11, 2024
da82c73
moree
dimaMachina Nov 11, 2024
7bdefb3
moree
dimaMachina Nov 11, 2024
6021ee0
moree
dimaMachina Nov 11, 2024
bff02d5
moree
dimaMachina Nov 11, 2024
62e1240
moree
dimaMachina Nov 11, 2024
31e41ca
moree
dimaMachina Nov 11, 2024
6b0f1f8
moree
dimaMachina Nov 11, 2024
d31b5c7
moree
dimaMachina Nov 11, 2024
7e17c93
moree
dimaMachina Nov 12, 2024
5873059
more
dimaMachina Nov 12, 2024
e8a8efa
more
dimaMachina Nov 12, 2024
cfea090
more
dimaMachina Nov 12, 2024
564f014
more
dimaMachina Nov 12, 2024
260b9fe
more
dimaMachina Nov 12, 2024
e33c218
[skip ci]
dimaMachina Nov 12, 2024
afd73d2
more
dimaMachina Nov 12, 2024
f45e611
more
dimaMachina Nov 12, 2024
80db90a
more
dimaMachina Nov 12, 2024
d3176c1
more
dimaMachina Nov 12, 2024
9df3e09
more
dimaMachina Nov 12, 2024
aec8b70
more
dimaMachina Nov 12, 2024
91e77cc
more
dimaMachina Nov 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/chilled-turkeys-smell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'nextra-theme-blog': major
'nextra-theme-docs': major
'nextra': major
---

make `compileMdx` from `nextra/compile` return a `string` instead of an `object`
12 changes: 6 additions & 6 deletions docs/app/docs/advanced/customize-the-cascade-layers/page.mdx
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
sidebarTitle: Customize Cascade Layers
---

import { Steps } from 'nextra/components'

# Customize the Cascade Layers
Expand Down Expand Up @@ -46,12 +50,8 @@ Import your CSS file at the top-level layout of your application (e.g.
```jsx filename="app/layout.jsx"
import '../path/to/your/styles.css'

export default function RootLayout({ children }) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
export default async function RootLayout({ children }) {
// ... Your layout logic here
}
```

Expand Down
8 changes: 6 additions & 2 deletions docs/app/docs/advanced/latex/page.mdx
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
icon: FormulaIcon
---

import { compileMdx } from 'nextra/compile'
import { MDXRemote } from 'nextra/mdx-remote'
import {
Expand Down Expand Up @@ -185,7 +189,7 @@ export async function MathJaxExample() {
\\int_2^3x^3\\,\\mathrm{d}x
~~~
`
const { result } = await compileMdx(
const rawJs = await compileMdx(
rawMdx,
{
latex: {
Expand All @@ -203,5 +207,5 @@ export async function MathJaxExample() {
}
)

return <MDXRemote compiledSource={result} components={{ MathJax, MathJaxContext }} />
return <MDXRemote compiledSource={rawJs} components={{ MathJax, MathJaxContext }} />
}
8 changes: 6 additions & 2 deletions docs/app/docs/advanced/mermaid/page.mdx
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
icon: DiagramIcon
---

import { compileMdx } from 'nextra/compile'
import { Mermaid } from 'nextra/components'
import { MDXRemote } from 'nextra/mdx-remote'
Expand Down Expand Up @@ -35,13 +39,13 @@ Z --> E;
Z --> F;
Z --> G;
\`\`\``
const { result } = await compileMdx(`${mermaidCodeblock}
const rawJs = await compileMdx(`${mermaidCodeblock}

## Usage

~~~md filename="Markdown"
${mermaidCodeblock}
~~~
`)
return <MDXRemote compiledSource={result} components={{ Mermaid }} />
return <MDXRemote compiledSource={rawJs} components={{ Mermaid }} />
}
8 changes: 6 additions & 2 deletions docs/app/docs/advanced/npm2yarn/page.mdx
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
icon: TerminalIcon
---

import { compileMdx } from 'nextra/compile'
import { Tabs } from 'nextra/components'
import { MDXRemote } from 'nextra/mdx-remote'
Expand All @@ -21,11 +25,11 @@ export async function Page() {
const codeBlock = `\`\`\`sh npm2yarn
npm i -D @graphql-eslint/eslint-plugin
\`\`\``
const { result } = await compileMdx(`${codeBlock}
const rawJs = await compileMdx(`${codeBlock}
## Usage

~~~md filename="Markdown" /npm2yarn/
${codeBlock}
~~~`)
return <MDXRemote compiledSource={result} components={{ $Tabs: Tabs }} />
return <MDXRemote compiledSource={rawJs} components={{ $Tabs: Tabs }} />
}
58 changes: 15 additions & 43 deletions docs/app/docs/advanced/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,49 +11,21 @@ import {
} from '@components/icons'
import { Cards } from 'nextra/components'
import { TerminalIcon, TypeScriptIcon } from 'nextra/icons'
import { MDXRemote } from 'nextra/mdx-remote'
import { createIndexPage, getPageMap } from 'nextra/page-map'

# Advanced

<Cards>
<Cards.Card
icon={<TerminalIcon />}
title="Npm2Yarn"
href="/docs/advanced/npm2yarn"
/>
<Cards.Card
icon={<DiagramIcon />}
title="Mermaid"
href="/docs/advanced/mermaid"
/>
<Cards.Card
icon={<TailwindIcon />}
title="Tailwind CSS"
href="/docs/advanced/tailwind-css"
/>
<Cards.Card
icon={<FormulaIcon />}
title="LaTeX"
href="/docs/advanced/latex"
/>
<Cards.Card
icon={<TableIcon />}
title="Rendering Tables"
href="/docs/advanced/table"
/>
<Cards.Card
icon={<TypeScriptIcon />}
title="TypeScript"
href="/docs/advanced/typescript"
/>
<Cards.Card
icon={<CloudIcon />}
title="Remote Content"
href="/docs/advanced/remote"
/>
<Cards.Card title="Playground" href="/docs/advanced/playground" />
<Cards.Card
title="Customize Cascade Layers"
href="/docs/advanced/customize-the-cascade-layers"
/>
<Cards.Card title="Twoslash Support" href="/docs/advanced/twoslash-support" />
</Cards>
<MDXRemote
compiledSource={await createIndexPage(await getPageMap('', '/docs/advanced'))}
components={{
Cards,
TerminalIcon,
DiagramIcon,
TailwindIcon,
FormulaIcon,
TableIcon,
TypeScriptIcon,
CloudIcon
}}
/>
4 changes: 4 additions & 0 deletions docs/app/docs/advanced/remote/page.mdx
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
icon: CloudIcon
---

# Remote Content

import { Callout } from 'nextra/components'
Expand Down
4 changes: 4 additions & 0 deletions docs/app/docs/advanced/table/page.mdx
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
icon: TableIcon
---

import { Callout, Table } from 'nextra/components'

# Rendering Tables
Expand Down
50 changes: 39 additions & 11 deletions docs/app/docs/advanced/tailwind-css/page.mdx
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
---
icon: TailwindIcon
---

import { Steps } from 'nextra/components'

# Tailwind CSS

Tailwind CSS is a CSS framework that provides a set of pre-defined CSS classes
to quickly style elements. You can follow the official
[Tailwind CSS documentation for Next.js](https://tailwindcss.com/docs/guides/nextjs)
to set up Tailwind CSS for your Nextra project.

<Steps>

## Create `tailwind.config.js` file

To use Tailwind classes in your Markdown files, you will also need to add `.md`
and `.mdx` files to the `content` list in `tailwind.config.js`:

```js filename="tailwind.config.js" /md,mdx/
/** @type {import('tailwindcss').Config} */
module.exports = {
export default {
content: [
'./pages/**/*.{js,jsx,ts,tsx,md,mdx}',
'./components/**/*.{js,jsx,ts,tsx,md,mdx}',
'./app/**/*.{js,jsx,ts,tsx,md,mdx}',
'./content/**/*.{md,mdx}',

// Or if using `src` directory:
'./src/**/*.{js,jsx,ts,tsx,md,mdx}'
Expand All @@ -25,20 +35,38 @@ module.exports = {
}
```

Next step, create a CSS file for Tailwind directives, `globals.css` for example:
> [!TIP]
>
> You can also use a `tailwind.config.ts` file if you prefer TypeScript for your
> Tailwind CSS configuration.

## Create the `globals.css` file

Create a CSS file for Tailwind directives, `globals.css` for example:

```css filename="globals.css"
@tailwind base;
@tailwind components;
@tailwind utilities;
@tailwind base; /* Apply Tailwind's base styles (Preflight) */
@tailwind components; /* Include component styles */
@tailwind utilities; /* Include utility classes */
```

Then import into `pages/_app.jsx`
> [!NOTE]
>
> If you're using `nextra-theme-docs` or `nextra-theme-blog`, you don't need to
> include the `@tailwind base` directive. These themes already import Tailwind's
> preflight styles in their `style.css` files.

## Import styles in the Root Layout

```jsx filename="_app.jsx"
To apply the styles globally, import the `globals.css` file in your root layout
file:

```jsx filename="app/layout.jsx"
import '../path/to/your/globals.css'

export default function App({ Component, pageProps }) {
return <Component {...pageProps} />
export default async function RootLayout({ children }) {
// ... Your layout logic here
}
```

</Steps>
4 changes: 4 additions & 0 deletions docs/app/docs/advanced/typescript/page.mdx
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
icon: TypeScriptIcon
---

import { Steps } from 'nextra/components'

# TypeScript
Expand Down
18 changes: 11 additions & 7 deletions docs/app/docs/blog-theme/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ sidebarTitle: Blog Theme

import { ChevronRightIcon } from '@components/icons'
import { Cards } from 'nextra/components'
import { MDXRemote } from 'nextra/mdx-remote'
import { createIndexPage, getPageMap } from 'nextra/page-map'

# Nextra Blog Theme

<Cards>
<Cards.Card
icon={<ChevronRightIcon />}
title="Get Started"
href="/docs/blog-theme/start"
/>
</Cards>
<MDXRemote
compiledSource={await createIndexPage(
await getPageMap('', '/docs/blog-theme')
)}
components={{
Cards,
ChevronRightIcon
}}
/>
26 changes: 4 additions & 22 deletions docs/app/docs/blog-theme/start/page.mdx
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
icon: ChevronRightIcon
---

import InstallNextraTheme from '@components/install-nextra-theme.mdx'
import ReadeToGo from '@components/ready-to-go.mdx'
import { Steps } from 'nextra/components'
Expand Down Expand Up @@ -32,28 +36,6 @@ npm i next react react-dom nextra nextra-theme-blog

<InstallNextraTheme />

### Add Next.js Config

Create the following `next.config.mjs` file in your project's root directory:

```js filename="next.config.mjs"
import nextra from 'nextra'

const withNextra = nextra({
theme: 'nextra-theme-blog',
themeConfig: './theme.config.jsx'
})

export default withNextra()

// If you have other Next.js configurations, you can pass them as the parameter:
// export default withNextra({ /* other next.js config */ })
```

With the above configuration, Nextra can handle Markdown files in your Next.js
project, with the specified theme. Other Nextra configurations can be found in
[Guide](/docs/guide).

### Create Blog Theme Config

Lastly, create the corresponding `theme.config.jsx` file in your project's root
Expand Down
4 changes: 2 additions & 2 deletions docs/app/docs/built-ins/cards/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export async function CardsPage() {
href="/docs/guide/built-ins/steps"
/>
</Cards>`
const { result } = await compileMdx(`
const rawJs = await compileMdx(`
## Grouped Cards

### Example
Expand Down Expand Up @@ -76,7 +76,7 @@ ${mdx2}
~~~mdx filename="MDX"
${mdx2}
~~~`)
return <MDXRemote compiledSource={result} components={{ Cards, CardsIcon, OneIcon, WarningIcon, BoxIcon }} />
return <MDXRemote compiledSource={rawJs} components={{ Cards, CardsIcon, OneIcon, WarningIcon, BoxIcon }} />
}

<CardsPage />
4 changes: 2 additions & 2 deletions docs/app/docs/built-ins/filetree/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ A built-in component to visually represent a file tree.
Click the folder to test the dynamic functionality of the file tree.

<FileTree>
<FileTree.Folder name="pages" defaultOpen>
<FileTree.Folder name="content" defaultOpen>
<FileTree.File name="_meta.js" />
<FileTree.File name="contact.md" />
<FileTree.File name="index.mdx" />
Expand All @@ -36,7 +36,7 @@ with the `name` attribute. Use `defaultOpen` to set the folder to open on load.
import { FileTree } from 'nextra/components'

<FileTree>
<FileTree.Folder name="pages" defaultOpen>
<FileTree.Folder name="content" defaultOpen>
<FileTree.File name="_meta.js" />
<FileTree.File name="contact.md" />
<FileTree.File name="index.mdx" />
Expand Down
Loading