@astrojs/mdx 1.0.0-beta.2 → 1.0.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.
- package/README.md +83 -19
- package/dist/index.d.ts +4 -2
- package/dist/index.js +83 -35
- package/dist/plugins.d.ts +4 -5
- package/dist/plugins.js +36 -80
- package/dist/rehype-collect-headings.d.ts +1 -1
- package/dist/rehype-meta-string.js +2 -3
- package/dist/rehype-optimize-static.d.ts +11 -0
- package/dist/rehype-optimize-static.js +62 -0
- package/dist/remark-images-to-component.d.ts +2 -0
- package/dist/remark-images-to-component.js +83 -0
- package/dist/utils.d.ts +2 -1
- package/dist/utils.js +23 -15
- package/package.json +39 -30
- package/template/content-module-types.d.ts +9 -0
- package/.turbo/turbo-build.log +0 -5
- package/CHANGELOG.md +0 -469
- package/src/index.ts +0 -201
- package/src/plugins.ts +0 -246
- package/src/rehype-collect-headings.ts +0 -11
- package/src/rehype-meta-string.ts +0 -17
- package/src/remark-prism.ts +0 -18
- package/src/remark-shiki.ts +0 -95
- package/src/utils.ts +0 -102
- package/test/fixtures/mdx-astro-markdown-remarkRehype/src/pages/index.mdx +0 -5
- package/test/fixtures/mdx-component/src/components/Test.mdx +0 -3
- package/test/fixtures/mdx-component/src/components/WithFragment.mdx +0 -3
- package/test/fixtures/mdx-component/src/pages/glob.astro +0 -20
- package/test/fixtures/mdx-component/src/pages/index.astro +0 -5
- package/test/fixtures/mdx-component/src/pages/w-fragment.astro +0 -5
- package/test/fixtures/mdx-escape/src/components/Em.astro +0 -7
- package/test/fixtures/mdx-escape/src/components/P.astro +0 -1
- package/test/fixtures/mdx-escape/src/components/Title.astro +0 -1
- package/test/fixtures/mdx-escape/src/pages/html-tag.mdx +0 -5
- package/test/fixtures/mdx-escape/src/pages/index.mdx +0 -13
- package/test/fixtures/mdx-frontmatter/src/layouts/Base.astro +0 -38
- package/test/fixtures/mdx-frontmatter/src/pages/glob.json.js +0 -9
- package/test/fixtures/mdx-frontmatter/src/pages/index.mdx +0 -10
- package/test/fixtures/mdx-frontmatter/src/pages/with-headings.mdx +0 -7
- package/test/fixtures/mdx-frontmatter-injection/astro.config.mjs +0 -12
- package/test/fixtures/mdx-frontmatter-injection/node_modules/.bin/astro +0 -17
- package/test/fixtures/mdx-frontmatter-injection/package.json +0 -12
- package/test/fixtures/mdx-frontmatter-injection/src/layouts/Base.astro +0 -17
- package/test/fixtures/mdx-frontmatter-injection/src/markdown-plugins.mjs +0 -27
- package/test/fixtures/mdx-frontmatter-injection/src/pages/glob.json.js +0 -6
- package/test/fixtures/mdx-frontmatter-injection/src/pages/page-1.mdx +0 -8
- package/test/fixtures/mdx-frontmatter-injection/src/pages/page-2.mdx +0 -24
- package/test/fixtures/mdx-get-headings/src/pages/pages.json.js +0 -11
- package/test/fixtures/mdx-get-headings/src/pages/test-with-jsx-expressions.mdx +0 -8
- package/test/fixtures/mdx-get-headings/src/pages/test.mdx +0 -9
- package/test/fixtures/mdx-get-static-paths/src/content/1.mdx +0 -5
- package/test/fixtures/mdx-get-static-paths/src/pages/[slug].astro +0 -34
- package/test/fixtures/mdx-infinite-loop/astro.config.ts +0 -6
- package/test/fixtures/mdx-infinite-loop/node_modules/.bin/astro +0 -17
- package/test/fixtures/mdx-infinite-loop/package.json +0 -10
- package/test/fixtures/mdx-infinite-loop/src/components/Test.js +0 -3
- package/test/fixtures/mdx-infinite-loop/src/pages/doc.mdx +0 -6
- package/test/fixtures/mdx-infinite-loop/src/pages/index.astro +0 -5
- package/test/fixtures/mdx-namespace/astro.config.mjs +0 -6
- package/test/fixtures/mdx-namespace/node_modules/.bin/astro +0 -17
- package/test/fixtures/mdx-namespace/package.json +0 -10
- package/test/fixtures/mdx-namespace/src/components/Component.jsx +0 -6
- package/test/fixtures/mdx-namespace/src/pages/object.mdx +0 -3
- package/test/fixtures/mdx-namespace/src/pages/star.mdx +0 -3
- package/test/fixtures/mdx-page/astro.config.ts +0 -5
- package/test/fixtures/mdx-page/node_modules/.bin/astro +0 -17
- package/test/fixtures/mdx-page/package.json +0 -9
- package/test/fixtures/mdx-page/src/pages/index.mdx +0 -3
- package/test/fixtures/mdx-page/src/styles.css +0 -3
- package/test/fixtures/mdx-plugins/src/pages/with-plugins.mdx +0 -25
- package/test/fixtures/mdx-plus-react/astro.config.mjs +0 -6
- package/test/fixtures/mdx-plus-react/node_modules/.bin/astro +0 -17
- package/test/fixtures/mdx-plus-react/package.json +0 -10
- package/test/fixtures/mdx-plus-react/src/components/Component.jsx +0 -5
- package/test/fixtures/mdx-plus-react/src/pages/index.astro +0 -11
- package/test/fixtures/mdx-slots/src/components/Slotted.astro +0 -4
- package/test/fixtures/mdx-slots/src/components/Test.mdx +0 -15
- package/test/fixtures/mdx-slots/src/pages/glob.astro +0 -11
- package/test/fixtures/mdx-slots/src/pages/index.astro +0 -5
- package/test/fixtures/mdx-syntax-hightlighting/src/pages/index.mdx +0 -9
- package/test/fixtures/mdx-url-export/src/pages/pages.json.js +0 -9
- package/test/fixtures/mdx-url-export/src/pages/test-1.mdx +0 -1
- package/test/fixtures/mdx-url-export/src/pages/test-2.mdx +0 -1
- package/test/fixtures/mdx-url-export/src/pages/with-url-override.mdx +0 -3
- package/test/fixtures/mdx-vite-env-vars/astro.config.mjs +0 -9
- package/test/fixtures/mdx-vite-env-vars/node_modules/.bin/astro +0 -17
- package/test/fixtures/mdx-vite-env-vars/package.json +0 -7
- package/test/fixtures/mdx-vite-env-vars/src/pages/frontmatter.json.js +0 -7
- package/test/fixtures/mdx-vite-env-vars/src/pages/vite-env-vars.mdx +0 -38
- package/test/mdx-astro-markdown-remarkRehype.test.js +0 -85
- package/test/mdx-component.test.js +0 -191
- package/test/mdx-escape.test.js +0 -32
- package/test/mdx-frontmatter-injection.test.js +0 -53
- package/test/mdx-frontmatter.test.js +0 -77
- package/test/mdx-get-headings.test.js +0 -151
- package/test/mdx-get-static-paths.test.js +0 -32
- package/test/mdx-infinite-loop.test.js +0 -30
- package/test/mdx-namespace.test.js +0 -83
- package/test/mdx-page.test.js +0 -64
- package/test/mdx-plugins.test.js +0 -250
- package/test/mdx-plus-react.test.js +0 -25
- package/test/mdx-slots.js +0 -124
- package/test/mdx-syntax-highlighting.test.js +0 -145
- package/test/mdx-url-export.test.js +0 -28
- package/test/mdx-vite-env-vars.test.js +0 -54
- package/tsconfig.json +0 -10
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
#!/bin/sh
|
|
2
|
-
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
|
3
|
-
|
|
4
|
-
case `uname` in
|
|
5
|
-
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
|
|
6
|
-
esac
|
|
7
|
-
|
|
8
|
-
if [ -z "$NODE_PATH" ]; then
|
|
9
|
-
export NODE_PATH="/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
|
|
10
|
-
else
|
|
11
|
-
export NODE_PATH="$NODE_PATH:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
|
|
12
|
-
fi
|
|
13
|
-
if [ -x "$basedir/node" ]; then
|
|
14
|
-
exec "$basedir/node" "$basedir/../../../../../../../astro/astro.js" "$@"
|
|
15
|
-
else
|
|
16
|
-
exec node "$basedir/../../../../../../../astro/astro.js" "$@"
|
|
17
|
-
fi
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@test/mdx-frontmatter-injection",
|
|
3
|
-
"version": "0.0.0",
|
|
4
|
-
"private": true,
|
|
5
|
-
"dependencies": {
|
|
6
|
-
"astro": "workspace:*",
|
|
7
|
-
"@astrojs/mdx": "workspace:*",
|
|
8
|
-
"mdast-util-to-string": "^3.1.0",
|
|
9
|
-
"reading-time": "^1.5.0",
|
|
10
|
-
"unist-util-visit": "^4.1.0"
|
|
11
|
-
}
|
|
12
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
const defaults = { title: 'Frontmatter not passed to layout!' }
|
|
3
|
-
const { frontmatter = defaults, content = defaults } = Astro.props;
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
<!DOCTYPE html>
|
|
7
|
-
<html lang="en">
|
|
8
|
-
<head>
|
|
9
|
-
<meta charset="UTF-8">
|
|
10
|
-
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
11
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
12
|
-
<title>{frontmatter.title}</title>
|
|
13
|
-
</head>
|
|
14
|
-
<body>
|
|
15
|
-
<slot />
|
|
16
|
-
</body>
|
|
17
|
-
</html>
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import getReadingTime from 'reading-time';
|
|
2
|
-
import { toString } from 'mdast-util-to-string';
|
|
3
|
-
import { visit } from 'unist-util-visit';
|
|
4
|
-
|
|
5
|
-
export function rehypeReadingTime() {
|
|
6
|
-
return function (tree, { data }) {
|
|
7
|
-
const readingTime = getReadingTime(toString(tree));
|
|
8
|
-
data.astro.frontmatter.injectedReadingTime = readingTime;
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function remarkTitle() {
|
|
13
|
-
return function (tree, { data }) {
|
|
14
|
-
visit(tree, ['heading'], (node) => {
|
|
15
|
-
if (node.depth === 1) {
|
|
16
|
-
data.astro.frontmatter.title = toString(node.children);
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function remarkDescription() {
|
|
23
|
-
return function (tree, vfile) {
|
|
24
|
-
const { frontmatter } = vfile.data.astro;
|
|
25
|
-
frontmatter.description = `Processed by remarkDescription plugin: ${frontmatter.description}`
|
|
26
|
-
};
|
|
27
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
layout: '../layouts/Base.astro'
|
|
3
|
-
description: Page 2 description
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# Page 2
|
|
7
|
-
|
|
8
|
-
## Table of contents
|
|
9
|
-
|
|
10
|
-
## Section 1
|
|
11
|
-
|
|
12
|
-
Some text!
|
|
13
|
-
|
|
14
|
-
### Subsection 1
|
|
15
|
-
|
|
16
|
-
Some subsection test!
|
|
17
|
-
|
|
18
|
-
### Subsection 2
|
|
19
|
-
|
|
20
|
-
Oh cool, more text!
|
|
21
|
-
|
|
22
|
-
## Section 2
|
|
23
|
-
|
|
24
|
-
More content
|
|
@@ -1,11 +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
|
-
headingsByPage: Object.fromEntries(
|
|
7
|
-
Object.entries(mdxPages ?? {}).map(([k, v]) => [k, v?.getHeadings()])
|
|
8
|
-
),
|
|
9
|
-
}),
|
|
10
|
-
}
|
|
11
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
export const getStaticPaths = async () => {
|
|
3
|
-
const content = await Astro.glob('../content/*.mdx');
|
|
4
|
-
|
|
5
|
-
return content
|
|
6
|
-
.filter((page) => !page.frontmatter.draft) // skip drafts
|
|
7
|
-
.map(({ default: MdxContent, frontmatter, url, file }) => {
|
|
8
|
-
return {
|
|
9
|
-
params: { slug: frontmatter.slug || "index" },
|
|
10
|
-
props: {
|
|
11
|
-
MdxContent,
|
|
12
|
-
file,
|
|
13
|
-
frontmatter,
|
|
14
|
-
url
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
})
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const { MdxContent, frontmatter, url, file } = Astro.props;
|
|
21
|
-
---
|
|
22
|
-
|
|
23
|
-
<html>
|
|
24
|
-
<head>
|
|
25
|
-
<title>Page</title>
|
|
26
|
-
</head>
|
|
27
|
-
<body>
|
|
28
|
-
<MdxContent />
|
|
29
|
-
|
|
30
|
-
<div id="one">{frontmatter.one}</div>
|
|
31
|
-
<div id="url">{url}</div>
|
|
32
|
-
<div id="file">{file}</div>
|
|
33
|
-
</body>
|
|
34
|
-
</html>
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
#!/bin/sh
|
|
2
|
-
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
|
3
|
-
|
|
4
|
-
case `uname` in
|
|
5
|
-
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
|
|
6
|
-
esac
|
|
7
|
-
|
|
8
|
-
if [ -z "$NODE_PATH" ]; then
|
|
9
|
-
export NODE_PATH="/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
|
|
10
|
-
else
|
|
11
|
-
export NODE_PATH="$NODE_PATH:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
|
|
12
|
-
fi
|
|
13
|
-
if [ -x "$basedir/node" ]; then
|
|
14
|
-
exec "$basedir/node" "$basedir/../../../../../../../astro/astro.js" "$@"
|
|
15
|
-
else
|
|
16
|
-
exec node "$basedir/../../../../../../../astro/astro.js" "$@"
|
|
17
|
-
fi
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
#!/bin/sh
|
|
2
|
-
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
|
3
|
-
|
|
4
|
-
case `uname` in
|
|
5
|
-
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
|
|
6
|
-
esac
|
|
7
|
-
|
|
8
|
-
if [ -z "$NODE_PATH" ]; then
|
|
9
|
-
export NODE_PATH="/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
|
|
10
|
-
else
|
|
11
|
-
export NODE_PATH="$NODE_PATH:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
|
|
12
|
-
fi
|
|
13
|
-
if [ -x "$basedir/node" ]; then
|
|
14
|
-
exec "$basedir/node" "$basedir/../../../../../../../astro/astro.js" "$@"
|
|
15
|
-
else
|
|
16
|
-
exec node "$basedir/../../../../../../../astro/astro.js" "$@"
|
|
17
|
-
fi
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
#!/bin/sh
|
|
2
|
-
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
|
3
|
-
|
|
4
|
-
case `uname` in
|
|
5
|
-
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
|
|
6
|
-
esac
|
|
7
|
-
|
|
8
|
-
if [ -z "$NODE_PATH" ]; then
|
|
9
|
-
export NODE_PATH="/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
|
|
10
|
-
else
|
|
11
|
-
export NODE_PATH="$NODE_PATH:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
|
|
12
|
-
fi
|
|
13
|
-
if [ -x "$basedir/node" ]; then
|
|
14
|
-
exec "$basedir/node" "$basedir/../../../../../../../astro/astro.js" "$@"
|
|
15
|
-
else
|
|
16
|
-
exec node "$basedir/../../../../../../../astro/astro.js" "$@"
|
|
17
|
-
fi
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
export let recmaPluginWorking = false
|
|
2
|
-
|
|
3
|
-
# TOC test
|
|
4
|
-
|
|
5
|
-
## Table of contents
|
|
6
|
-
|
|
7
|
-
## Section 1
|
|
8
|
-
|
|
9
|
-
Some text!
|
|
10
|
-
|
|
11
|
-
### Subsection 1
|
|
12
|
-
|
|
13
|
-
Some subsection test!
|
|
14
|
-
|
|
15
|
-
### Subsection 2
|
|
16
|
-
|
|
17
|
-
Oh cool, more text!
|
|
18
|
-
|
|
19
|
-
## Section 2
|
|
20
|
-
|
|
21
|
-
And section 2, with a hyperlink to check GFM is preserved: https://handle-me-gfm.com
|
|
22
|
-
|
|
23
|
-
<div data-recma-plugin-works={recmaPluginWorking}></div>
|
|
24
|
-
|
|
25
|
-
> "Smartypants" is -- awesome
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
#!/bin/sh
|
|
2
|
-
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
|
3
|
-
|
|
4
|
-
case `uname` in
|
|
5
|
-
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
|
|
6
|
-
esac
|
|
7
|
-
|
|
8
|
-
if [ -z "$NODE_PATH" ]; then
|
|
9
|
-
export NODE_PATH="/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
|
|
10
|
-
else
|
|
11
|
-
export NODE_PATH="$NODE_PATH:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
|
|
12
|
-
fi
|
|
13
|
-
if [ -x "$basedir/node" ]; then
|
|
14
|
-
exec "$basedir/node" "$basedir/../../../../../../../astro/astro.js" "$@"
|
|
15
|
-
else
|
|
16
|
-
exec node "$basedir/../../../../../../../astro/astro.js" "$@"
|
|
17
|
-
fi
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
# I'm a page with a url of "/test-1!"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
# I'm a page with a url of "/test-2!"
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
#!/bin/sh
|
|
2
|
-
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
|
3
|
-
|
|
4
|
-
case `uname` in
|
|
5
|
-
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
|
|
6
|
-
esac
|
|
7
|
-
|
|
8
|
-
if [ -z "$NODE_PATH" ]; then
|
|
9
|
-
export NODE_PATH="/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
|
|
10
|
-
else
|
|
11
|
-
export NODE_PATH="$NODE_PATH:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
|
|
12
|
-
fi
|
|
13
|
-
if [ -x "$basedir/node" ]; then
|
|
14
|
-
exec "$basedir/node" "$basedir/../../../../../../../astro/astro.js" "$@"
|
|
15
|
-
else
|
|
16
|
-
exec node "$basedir/../../../../../../../astro/astro.js" "$@"
|
|
17
|
-
fi
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Let's talk about my import.meta.env.SITE
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
export const modeWorks =
|
|
6
|
-
import.meta.env.MODE === 'production' ? 'MODE works' : 'MODE does not work!';
|
|
7
|
-
|
|
8
|
-
# About my import.meta.env.SITE
|
|
9
|
-
|
|
10
|
-
My `import.meta.env.SITE` is so cool, I can put env variables in code!
|
|
11
|
-
|
|
12
|
-
```js
|
|
13
|
-
const site = import.meta.env.SITE;
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
## But I can use import.meta.env properly too
|
|
17
|
-
|
|
18
|
-
<div data-env-site>
|
|
19
|
-
|
|
20
|
-
I can compute my site, for example: {new URL('/blog/cool-post', import.meta.env.SITE)}
|
|
21
|
-
|
|
22
|
-
</div>
|
|
23
|
-
|
|
24
|
-
<div data-env-variable-exports>
|
|
25
|
-
|
|
26
|
-
I can also use `import.meta.env` in variable exports: {modeWorks}
|
|
27
|
-
|
|
28
|
-
</div>
|
|
29
|
-
|
|
30
|
-
I can also use vars as HTML attributes:
|
|
31
|
-
|
|
32
|
-
<div
|
|
33
|
-
data-env-dump
|
|
34
|
-
data-env-prod={import.meta.env.PROD}
|
|
35
|
-
data-env-dev={import.meta.env.DEV}
|
|
36
|
-
data-env-base-url={import.meta.env.BASE_URL}
|
|
37
|
-
data-env-mode={import.meta.env.MODE}
|
|
38
|
-
></div>
|