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

Preserve JSX from MDX #62

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
src/content/*.js linguist-generated=true
src/content/*.jsx linguist-generated=true
**/*.gen.ts linguist-generated=true
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ cov/
cov.lcov

# Compiled MDX
src/content/**/*.js
src/content/**/*.jsx
2 changes: 1 addition & 1 deletion src/routes/solutions/[category]/[[slug]].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const handler: Handlers<SolutionProps> = {
}

const extensionless = join(contentDir, category, slug);
const filepath = `${extensionless}.js`;
const filepath = `${extensionless}.jsx`;

const file: MDXModule = await import(filepath);

Expand Down
44 changes: 22 additions & 22 deletions src/utils/imports.gen.ts

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

3 changes: 2 additions & 1 deletion tool/compile-mdx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ const rehypePlugins = [rehypeMathjax] as const satisfies PluggableList;
/** MDX compilation options. */
const compileOptions = {
jsxImportSource: "preact",
jsx: true,
rehypePlugins,
remarkPlugins,
} as const satisfies CompileOptions;
Expand All @@ -180,7 +181,7 @@ async function compileSolution(file: VFile): Promise<VFile> {
matter(file); // Extract the frontmatter into `data.matter`.

const compiled = await compile(file, compileOptions);
compiled.extname = ".js";
compiled.extname = ".jsx";

// @ts-expect-error: The types are a bit off, but I'm feeling lazy.
compiled.data.matter.category =
Expand Down