Skip to content

Commit

Permalink
fix mdx not rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
shairez committed Dec 16, 2024
1 parent d70d709 commit 56e43f6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/long-jobs-whisper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@builder.io/qwik-city': patch
---

FIX: mdx not rendering
19 changes: 15 additions & 4 deletions packages/qwik-city/src/buildtime/markdown/mdx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { BuildContext } from '../types';
import { parseFrontmatter } from './frontmatter';
import { getExtension } from '../../utils/fs';
import type { CompileOptions } from '@mdx-js/mdx';
import { createHash } from 'node:crypto';

export async function createMdxTransformer(ctx: BuildContext): Promise<MdxTransform> {
const { compile } = await import('@mdx-js/mdx');
Expand Down Expand Up @@ -69,11 +70,21 @@ export async function createMdxTransformer(ctx: BuildContext): Promise<MdxTransf
const file = new VFile({ value: code, path: id });
const compiled = await compile(file, options);
const output = String(compiled.value);
const addImport = `import { jsx } from '@builder.io/qwik';\n`;
const newDefault = `
const hasher = createHash('sha256');
const key = hasher
.update(output)
.digest('base64')
.slice(0, 8)
.replace('+', '-')
.replace('/', '_');
const addImport = `import { jsx, _jsxC, RenderOnce } from '@builder.io/qwik';\n`;
const newDefault = `
const WrappedMdxContent = () => {
const content = _createMdxContent({});
return typeof MDXLayout === 'function' ? jsx(MDXLayout, {children: content}) : content;
const content = _jsxC(RenderOnce, {children: _jsxC(_createMdxContent, {}, 3, null)}, 3, ${JSON.stringify(key)});
if (typeof MDXLayout === 'function'){
return jsx(MDXLayout, {children: content});
}
return content;
};
export default WrappedMdxContent;
`;
Expand Down

0 comments on commit 56e43f6

Please sign in to comment.