Skip to content

Commit

Permalink
chore(website): use new mdx package for the website
Browse files Browse the repository at this point in the history
  • Loading branch information
sdorra committed Mar 21, 2024
1 parent 77cac8e commit 0d3eca0
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 46 deletions.
42 changes: 21 additions & 21 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 2 additions & 10 deletions website/app/docs/[category]/[page]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { Sample, allIntegrations, allSamples } from "content-collections";
import { notFound } from "next/navigation";
import { run } from "@mdx-js/mdx";
import * as runtime from "react/jsx-runtime";
import { Fragment } from "react";
import { Metadata } from "next";
import { createStackBlitzLink } from "@/lib/stackblitz";
import {MDXContent} from "@content-collections/mdx/react";

type Props = {
params: {
Expand Down Expand Up @@ -54,17 +52,11 @@ export default async function Page({ params: { category, page } }: Props) {
return notFound();
}

const { default: Content } = await run(docPage.body, {
...runtime,
baseUrl: import.meta.url,
Fragment,
});

return (
<div className="min-w-0">
<article className="prose prose-base prose-code:text-base hover:prose-a:decoration-primary-600 max-w-3xl prose-invert py-5 px-5 sm:px-10">
<h1>{docPage.title}</h1>
<Content />
<MDXContent code={docPage.body} />
</article>
{isSample(category, docPage) ? <StackBlitz sample={docPage} /> : null}
</div>
Expand Down
17 changes: 6 additions & 11 deletions website/content-collections.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import { defineCollection, defineConfig } from "@content-collections/core";
import rehypeShiki from "@shikijs/rehype";
import { compile } from "@mdx-js/mdx";
import { Options, compileMDX } from "@content-collections/mdx";

async function mdx(content: string) {
return String(
await compile(content, {
outputFormat: "function-body",
rehypePlugins: [[rehypeShiki, { theme: "one-dark-pro" }]],
})
);
}
const mdxOptions: Options = {
rehypePlugins: [[rehypeShiki, { theme: "one-dark-pro" }]],
};

const integrations = defineCollection({
name: "integrations",
Expand All @@ -22,7 +17,7 @@ const integrations = defineCollection({
icon: z.string().optional(),
}),
transform: async (data, ctx) => {
const body = await ctx.cache(data.content, mdx);
const body = await compileMDX(ctx, data, mdxOptions);

let linkText = data.linkText;
if (!linkText) {
Expand Down Expand Up @@ -57,7 +52,7 @@ const samples = defineCollection({
.optional(),
}),
transform: async (data, ctx) => {
const body = await ctx.cache(data.content, mdx);
const body = await compileMDX(ctx, data, mdxOptions);

let linkText = data.linkText;
if (!linkText) {
Expand Down
8 changes: 4 additions & 4 deletions website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"lint": "next lint"
},
"dependencies": {
"@mdx-js/mdx": "^3.0.0",
"@radix-ui/react-radio-group": "^1.1.3",
"clsx": "^2.1.0",
"fathom-client": "^3.6.0",
Expand All @@ -24,8 +23,9 @@
"devDependencies": {
"@content-collections/core": "workspace:*",
"@content-collections/next": "workspace:*",
"@shikijs/rehype": "1.0.0-beta.6",
"@shikijs/transformers": "1.0.0-beta.6",
"@content-collections/mdx": "workspace:*",
"@shikijs/rehype": "1.2.0",
"@shikijs/transformers": "1.2.0",
"@tailwindcss/typography": "^0.5.10",
"@types/node": "^20",
"@types/react": "^18",
Expand All @@ -36,7 +36,7 @@
"eslint-config-next": "14.1.0",
"hast-util-to-jsx-runtime": "^2.3.0",
"postcss": "^8",
"shiki": "1.0.0-beta.6",
"shiki": "1.2.0",
"tailwindcss": "^3.4.0",
"typescript": "^5"
}
Expand Down

0 comments on commit 0d3eca0

Please sign in to comment.