@astrojs/mdx 0.5.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/.turbo/turbo-build.log +5 -5
  2. package/CHANGELOG.md +30 -0
  3. package/README.md +57 -76
  4. package/dist/astro-data-utils.d.ts +9 -0
  5. package/dist/astro-data-utils.js +47 -0
  6. package/dist/index.d.ts +0 -7
  7. package/dist/index.js +49 -44
  8. package/dist/utils.d.ts +2 -3
  9. package/dist/utils.js +4 -4
  10. package/package.json +4 -5
  11. package/src/astro-data-utils.ts +59 -0
  12. package/src/index.ts +63 -59
  13. package/src/utils.ts +2 -2
  14. package/test/fixtures/mdx-escape/src/components/Em.astro +7 -0
  15. package/test/fixtures/mdx-escape/src/components/P.astro +1 -0
  16. package/test/fixtures/mdx-escape/src/components/Title.astro +1 -0
  17. package/test/fixtures/mdx-escape/src/pages/html-tag.mdx +5 -0
  18. package/test/fixtures/mdx-escape/src/pages/index.mdx +13 -0
  19. package/test/fixtures/mdx-frontmatter/src/layouts/Base.astro +13 -3
  20. package/test/fixtures/mdx-frontmatter/src/pages/index.mdx +3 -0
  21. package/test/fixtures/mdx-frontmatter/src/pages/with-headings.mdx +7 -0
  22. package/test/fixtures/mdx-frontmatter-injection/astro.config.mjs +12 -0
  23. package/test/fixtures/mdx-frontmatter-injection/node_modules/.bin/astro +17 -0
  24. package/test/fixtures/mdx-frontmatter-injection/package.json +12 -0
  25. package/test/fixtures/mdx-frontmatter-injection/src/markdown-plugins.mjs +20 -0
  26. package/test/fixtures/mdx-frontmatter-injection/src/pages/glob.json.js +6 -0
  27. package/test/fixtures/mdx-frontmatter-injection/src/pages/page-1.mdx +3 -0
  28. package/test/fixtures/mdx-frontmatter-injection/src/pages/page-2.mdx +19 -0
  29. package/test/fixtures/mdx-frontmatter-injection/src/pages/with-overrides.mdx +7 -0
  30. package/test/fixtures/mdx-plus-react/astro.config.mjs +6 -0
  31. package/test/fixtures/mdx-plus-react/node_modules/.bin/astro +17 -0
  32. package/test/fixtures/mdx-plus-react/package.json +8 -0
  33. package/test/fixtures/mdx-plus-react/src/components/Component.jsx +5 -0
  34. package/test/fixtures/mdx-plus-react/src/pages/index.astro +11 -0
  35. package/test/fixtures/mdx-rehype-plugins/src/pages/reading-time.json.js +2 -2
  36. package/test/fixtures/mdx-remark-plugins/src/pages/headings-glob.json.js +6 -0
  37. package/test/mdx-escape.test.js +32 -0
  38. package/test/mdx-frontmatter-injection.test.js +44 -0
  39. package/test/mdx-frontmatter.test.js +20 -37
  40. package/test/mdx-plus-react.test.js +25 -0
  41. package/test/mdx-rehype-plugins.test.js +6 -17
  42. package/test/fixtures/mdx-custom-frontmatter-name/src/pages/glob.json.js +0 -9
  43. package/test/fixtures/mdx-custom-frontmatter-name/src/pages/index.mdx +0 -6
@@ -1,15 +1,15 @@
1
1
  import mdx from '@astrojs/mdx';
2
- import { jsToTreeNode } from '../dist/utils.js';
3
2
 
4
- import { expect } from 'chai';
5
- import { parseHTML } from 'linkedom';
6
3
  import getReadingTime from 'reading-time';
7
4
  import { toString } from 'mdast-util-to-string';
5
+ import { expect } from 'chai';
6
+ import { parseHTML } from 'linkedom';
7
+ import { jsToTreeNode } from '../dist/utils.js';
8
8
 
9
9
  import { loadFixture } from '../../../astro/test/test-utils.js';
10
10
 
11
- export function rehypeReadingTime() {
12
- return function (tree) {
11
+ function rehypeReadingTime() {
12
+ return function (tree, { data }) {
13
13
  const readingTime = getReadingTime(toString(tree));
14
14
  tree.children.unshift(
15
15
  jsToTreeNode(`export const readingTime = ${JSON.stringify(readingTime)}`)
@@ -34,19 +34,8 @@ describe('MDX rehype plugins', () => {
34
34
  await fixture.build();
35
35
  });
36
36
 
37
- it('removes default getHeadings', async () => {
38
- const html = await fixture.readFile('/space-ipsum/index.html');
39
- const { document } = parseHTML(html);
40
-
41
- const headings = [...document.querySelectorAll('h1, h2')];
42
- expect(headings.length).to.be.greaterThan(0);
43
- for (const heading of headings) {
44
- expect(heading.id).to.be.empty;
45
- }
46
- });
47
-
48
37
  it('supports custom rehype plugins - reading time', async () => {
49
- const readingTime = JSON.parse(await fixture.readFile('/reading-time.json'));
38
+ const { readingTime } = JSON.parse(await fixture.readFile('/reading-time.json'));
50
39
 
51
40
  expect(readingTime).to.not.be.null;
52
41
  expect(readingTime.text).to.match(/^\d+ min read/);
@@ -1,9 +0,0 @@
1
- export async function get() {
2
- const mdxPages = await import.meta.glob('./*.mdx', { eager: true });
3
-
4
- return {
5
- body: JSON.stringify({
6
- titles: Object.values(mdxPages ?? {}).map(v => v?.customFrontmatter?.title),
7
- })
8
- }
9
- }
@@ -1,6 +0,0 @@
1
- ---
2
- title: 'Using YAML frontmatter'
3
- illThrowIfIDontExist: "Oh no, that's scary!"
4
- ---
5
-
6
- # {customFrontmatter.illThrowIfIDontExist}