@astrojs/mdx
Advanced tools
Comparing version 0.8.3 to 0.9.0
# @astrojs/mdx | ||
## 0.9.0 | ||
### Minor Changes | ||
- [#4268](https://github.com/withastro/astro/pull/4268) [`f7afdb889`](https://github.com/withastro/astro/commit/f7afdb889fe4e97177958c8ec92f80c5f6e5cb51) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Align MD with MDX on layout props and "glob" import results: | ||
- Add `Content` to MDX | ||
- Add `file` and `url` to MDX frontmatter (layout import only) | ||
- Update glob types to reflect differences (lack of `rawContent` and `compiledContent`) | ||
### Patch Changes | ||
- [#4272](https://github.com/withastro/astro/pull/4272) [`24d2f7a6e`](https://github.com/withastro/astro/commit/24d2f7a6e6700c10c863f826f37bb653d70e3a83) Thanks [@natemoo-re](https://github.com/natemoo-re)! - Properly handle hydration for namespaced components | ||
## 0.8.3 | ||
@@ -4,0 +17,0 @@ |
@@ -25,2 +25,4 @@ import { jsToTreeNode } from "./utils.js"; | ||
const { layout, ...content } = frontmatter; | ||
content.file = file; | ||
content.url = url; | ||
content.astro = {}; | ||
@@ -27,0 +29,0 @@ Object.defineProperty(content.astro, 'headings', { |
@@ -18,2 +18,4 @@ import { compile as mdxCompile, nodeTypes } from "@mdx-js/mdx"; | ||
const DEFAULT_REHYPE_PLUGINS = []; | ||
const RAW_CONTENT_ERROR = "MDX does not support rawContent()! If you need to read the Markdown contents to calculate values (ex. reading time), we suggest injecting frontmatter via remark plugins. Learn more on our docs: https://docs.astro.build/en/guides/integrations-guide/mdx/#inject-frontmatter-via-remark-or-rehype-plugins"; | ||
const COMPILED_CONTENT_ERROR = "MDX does not support compiledContent()! If you need to read the HTML contents to calculate values (ex. reading time), we suggest injecting frontmatter via rehype plugins. Learn more on our docs: https://docs.astro.build/en/guides/integrations-guide/mdx/#inject-frontmatter-via-remark-or-rehype-plugins"; | ||
function handleExtends(config, defaults = []) { | ||
@@ -98,2 +100,18 @@ if (Array.isArray(config)) | ||
} | ||
if (!moduleExports.includes("rawContent")) { | ||
code += ` | ||
export function rawContent() { throw new Error(${JSON.stringify( | ||
RAW_CONTENT_ERROR | ||
)}) };`; | ||
} | ||
if (!moduleExports.includes("compiledContent")) { | ||
code += ` | ||
export function compiledContent() { throw new Error(${JSON.stringify( | ||
COMPILED_CONTENT_ERROR | ||
)}) };`; | ||
} | ||
if (!moduleExports.includes("Content")) { | ||
code += ` | ||
export const Content = MDXContent;`; | ||
} | ||
if (command === "dev") { | ||
@@ -100,0 +118,0 @@ code += ` |
{ | ||
"name": "@astrojs/mdx", | ||
"description": "Use MDX within Astro", | ||
"version": "0.8.3", | ||
"version": "0.9.0", | ||
"type": "module", | ||
@@ -46,3 +46,3 @@ "types": "./dist/index.d.ts", | ||
"@types/yargs-parser": "^21.0.0", | ||
"astro": "1.0.3", | ||
"astro": "1.0.4", | ||
"astro-scripts": "0.0.7", | ||
@@ -49,0 +49,0 @@ "chai": "^4.3.6", |
@@ -31,2 +31,4 @@ import type { MarkdownAstroData } from 'astro'; | ||
const { layout, ...content } = frontmatter; | ||
content.file = file; | ||
content.url = url; | ||
content.astro = {}; | ||
@@ -33,0 +35,0 @@ Object.defineProperty(content.astro, 'headings', { |
@@ -29,2 +29,8 @@ import { compile as mdxCompile, nodeTypes } from '@mdx-js/mdx'; | ||
const RAW_CONTENT_ERROR = | ||
'MDX does not support rawContent()! If you need to read the Markdown contents to calculate values (ex. reading time), we suggest injecting frontmatter via remark plugins. Learn more on our docs: https://docs.astro.build/en/guides/integrations-guide/mdx/#inject-frontmatter-via-remark-or-rehype-plugins'; | ||
const COMPILED_CONTENT_ERROR = | ||
'MDX does not support compiledContent()! If you need to read the HTML contents to calculate values (ex. reading time), we suggest injecting frontmatter via rehype plugins. Learn more on our docs: https://docs.astro.build/en/guides/integrations-guide/mdx/#inject-frontmatter-via-remark-or-rehype-plugins'; | ||
function handleExtends<T>(config: WithExtends<T[] | undefined>, defaults: T[] = []): T[] { | ||
@@ -131,2 +137,15 @@ if (Array.isArray(config)) return config; | ||
} | ||
if (!moduleExports.includes('rawContent')) { | ||
code += `\nexport function rawContent() { throw new Error(${JSON.stringify( | ||
RAW_CONTENT_ERROR | ||
)}) };`; | ||
} | ||
if (!moduleExports.includes('compiledContent')) { | ||
code += `\nexport function compiledContent() { throw new Error(${JSON.stringify( | ||
COMPILED_CONTENT_ERROR | ||
)}) };`; | ||
} | ||
if (!moduleExports.includes('Content')) { | ||
code += `\nexport const Content = MDXContent;`; | ||
} | ||
@@ -133,0 +152,0 @@ if (command === 'dev') { |
@@ -22,3 +22,3 @@ import mdx from '@astrojs/mdx'; | ||
it('works', async () => { | ||
it('supports top-level imports', async () => { | ||
const html = await fixture.readFile('/index.html'); | ||
@@ -33,2 +33,24 @@ const { document } = parseHTML(html); | ||
}); | ||
it('supports glob imports - <Component.default />', async () => { | ||
const html = await fixture.readFile('/glob/index.html'); | ||
const { document } = parseHTML(html); | ||
const h1 = document.querySelector('[data-default-export] h1'); | ||
const foo = document.querySelector('[data-default-export] #foo'); | ||
expect(h1.textContent).to.equal('Hello component!'); | ||
expect(foo.textContent).to.equal('bar'); | ||
}); | ||
it('supports glob imports - <Content />', async () => { | ||
const html = await fixture.readFile('/glob/index.html'); | ||
const { document } = parseHTML(html); | ||
const h1 = document.querySelector('[data-content-export] h1'); | ||
const foo = document.querySelector('[data-content-export] #foo'); | ||
expect(h1.textContent).to.equal('Hello component!'); | ||
expect(foo.textContent).to.equal('bar'); | ||
}); | ||
}); | ||
@@ -47,3 +69,3 @@ | ||
it('works', async () => { | ||
it('supports top-level imports', async () => { | ||
const res = await fixture.fetch('/'); | ||
@@ -62,3 +84,33 @@ | ||
}); | ||
it('supports glob imports - <Component.default />', async () => { | ||
const res = await fixture.fetch('/glob'); | ||
expect(res.status).to.equal(200); | ||
const html = await res.text(); | ||
const { document } = parseHTML(html); | ||
const h1 = document.querySelector('[data-default-export] h1'); | ||
const foo = document.querySelector('[data-default-export] #foo'); | ||
expect(h1.textContent).to.equal('Hello component!'); | ||
expect(foo.textContent).to.equal('bar'); | ||
}); | ||
it('supports glob imports - <Content />', async () => { | ||
const res = await fixture.fetch('/glob'); | ||
expect(res.status).to.equal(200); | ||
const html = await res.text(); | ||
const { document } = parseHTML(html); | ||
const h1 = document.querySelector('[data-content-export] h1'); | ||
const foo = document.querySelector('[data-content-export] #foo'); | ||
expect(h1.textContent).to.equal('Hello component!'); | ||
expect(foo.textContent).to.equal('bar'); | ||
}); | ||
}); | ||
}); |
@@ -59,2 +59,16 @@ import mdx from '@astrojs/mdx'; | ||
}); | ||
it('passes "file" and "url" to layout via frontmatter', async () => { | ||
const html = await fixture.readFile('/with-headings/index.html'); | ||
const { document } = parseHTML(html); | ||
const frontmatterFile = document.querySelector('[data-frontmatter-file]')?.textContent; | ||
const frontmatterUrl = document.querySelector('[data-frontmatter-url]')?.textContent; | ||
expect(frontmatterFile?.endsWith('with-headings.mdx')).to.equal( | ||
true, | ||
'"file" prop does not end with correct path or is undefined' | ||
); | ||
expect(frontmatterUrl).to.equal('/with-headings'); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
88608
85
1474
0