@astrojs/mdx 0.0.0-imgcache-20220929145446

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 (90) hide show
  1. package/.turbo/turbo-build.log +5 -0
  2. package/CHANGELOG.md +209 -0
  3. package/LICENSE +61 -0
  4. package/README.md +527 -0
  5. package/dist/index.d.ts +15 -0
  6. package/dist/index.js +131 -0
  7. package/dist/plugins.d.ts +11 -0
  8. package/dist/plugins.js +214 -0
  9. package/dist/rehype-collect-headings.d.ts +6 -0
  10. package/dist/rehype-collect-headings.js +47 -0
  11. package/dist/remark-prism.d.ts +2 -0
  12. package/dist/remark-prism.js +17 -0
  13. package/dist/remark-shiki.d.ts +3 -0
  14. package/dist/remark-shiki.js +69 -0
  15. package/dist/utils.d.ts +18 -0
  16. package/dist/utils.js +74 -0
  17. package/package.json +71 -0
  18. package/src/index.ts +167 -0
  19. package/src/plugins.ts +273 -0
  20. package/src/rehype-collect-headings.ts +50 -0
  21. package/src/remark-prism.ts +18 -0
  22. package/src/remark-shiki.ts +95 -0
  23. package/src/utils.ts +97 -0
  24. package/test/fixtures/mdx-component/src/components/Test.mdx +3 -0
  25. package/test/fixtures/mdx-component/src/pages/glob.astro +11 -0
  26. package/test/fixtures/mdx-component/src/pages/index.astro +5 -0
  27. package/test/fixtures/mdx-escape/src/components/Em.astro +7 -0
  28. package/test/fixtures/mdx-escape/src/components/P.astro +1 -0
  29. package/test/fixtures/mdx-escape/src/components/Title.astro +1 -0
  30. package/test/fixtures/mdx-escape/src/pages/html-tag.mdx +5 -0
  31. package/test/fixtures/mdx-escape/src/pages/index.mdx +13 -0
  32. package/test/fixtures/mdx-frontmatter/src/layouts/Base.astro +38 -0
  33. package/test/fixtures/mdx-frontmatter/src/pages/glob.json.js +9 -0
  34. package/test/fixtures/mdx-frontmatter/src/pages/index.mdx +10 -0
  35. package/test/fixtures/mdx-frontmatter/src/pages/with-headings.mdx +7 -0
  36. package/test/fixtures/mdx-frontmatter-injection/astro.config.mjs +12 -0
  37. package/test/fixtures/mdx-frontmatter-injection/node_modules/.bin/astro +17 -0
  38. package/test/fixtures/mdx-frontmatter-injection/package.json +12 -0
  39. package/test/fixtures/mdx-frontmatter-injection/src/layouts/Base.astro +17 -0
  40. package/test/fixtures/mdx-frontmatter-injection/src/markdown-plugins.mjs +20 -0
  41. package/test/fixtures/mdx-frontmatter-injection/src/pages/glob.json.js +6 -0
  42. package/test/fixtures/mdx-frontmatter-injection/src/pages/page-1.mdx +7 -0
  43. package/test/fixtures/mdx-frontmatter-injection/src/pages/page-2.mdx +23 -0
  44. package/test/fixtures/mdx-frontmatter-injection/src/pages/with-overrides.mdx +7 -0
  45. package/test/fixtures/mdx-get-headings/src/pages/pages.json.js +11 -0
  46. package/test/fixtures/mdx-get-headings/src/pages/test-with-jsx-expressions.mdx +8 -0
  47. package/test/fixtures/mdx-get-headings/src/pages/test.mdx +9 -0
  48. package/test/fixtures/mdx-get-static-paths/src/content/1.mdx +5 -0
  49. package/test/fixtures/mdx-get-static-paths/src/pages/[slug].astro +34 -0
  50. package/test/fixtures/mdx-namespace/astro.config.mjs +6 -0
  51. package/test/fixtures/mdx-namespace/node_modules/.bin/astro +17 -0
  52. package/test/fixtures/mdx-namespace/package.json +10 -0
  53. package/test/fixtures/mdx-namespace/src/components/Component.jsx +6 -0
  54. package/test/fixtures/mdx-namespace/src/pages/object.mdx +3 -0
  55. package/test/fixtures/mdx-namespace/src/pages/star.mdx +3 -0
  56. package/test/fixtures/mdx-page/astro.config.ts +5 -0
  57. package/test/fixtures/mdx-page/node_modules/.bin/astro +17 -0
  58. package/test/fixtures/mdx-page/package.json +9 -0
  59. package/test/fixtures/mdx-page/src/pages/index.mdx +3 -0
  60. package/test/fixtures/mdx-page/src/styles.css +3 -0
  61. package/test/fixtures/mdx-plugins/src/pages/with-plugins.mdx +19 -0
  62. package/test/fixtures/mdx-plus-react/astro.config.mjs +6 -0
  63. package/test/fixtures/mdx-plus-react/node_modules/.bin/astro +17 -0
  64. package/test/fixtures/mdx-plus-react/package.json +10 -0
  65. package/test/fixtures/mdx-plus-react/src/components/Component.jsx +5 -0
  66. package/test/fixtures/mdx-plus-react/src/pages/index.astro +11 -0
  67. package/test/fixtures/mdx-syntax-hightlighting/src/pages/index.mdx +9 -0
  68. package/test/fixtures/mdx-url-export/src/pages/pages.json.js +9 -0
  69. package/test/fixtures/mdx-url-export/src/pages/test-1.mdx +1 -0
  70. package/test/fixtures/mdx-url-export/src/pages/test-2.mdx +1 -0
  71. package/test/fixtures/mdx-url-export/src/pages/with-url-override.mdx +3 -0
  72. package/test/fixtures/mdx-vite-env-vars/astro.config.mjs +9 -0
  73. package/test/fixtures/mdx-vite-env-vars/node_modules/.bin/astro +17 -0
  74. package/test/fixtures/mdx-vite-env-vars/package.json +7 -0
  75. package/test/fixtures/mdx-vite-env-vars/src/pages/frontmatter.json.js +7 -0
  76. package/test/fixtures/mdx-vite-env-vars/src/pages/vite-env-vars.mdx +38 -0
  77. package/test/mdx-component.test.js +112 -0
  78. package/test/mdx-escape.test.js +32 -0
  79. package/test/mdx-frontmatter-injection.test.js +56 -0
  80. package/test/mdx-frontmatter.test.js +77 -0
  81. package/test/mdx-get-headings.test.js +60 -0
  82. package/test/mdx-get-static-paths.test.js +32 -0
  83. package/test/mdx-namespace.test.js +83 -0
  84. package/test/mdx-page.test.js +64 -0
  85. package/test/mdx-plugins.test.js +211 -0
  86. package/test/mdx-plus-react.test.js +25 -0
  87. package/test/mdx-syntax-highlighting.test.js +91 -0
  88. package/test/mdx-url-export.test.js +28 -0
  89. package/test/mdx-vite-env-vars.test.js +54 -0
  90. package/tsconfig.json +10 -0
@@ -0,0 +1,3 @@
1
+ # Hello component!
2
+
3
+ <div id="foo">bar</div>
@@ -0,0 +1,11 @@
1
+ ---
2
+ const components = await Astro.glob('../components/*.mdx');
3
+ ---
4
+
5
+ <div data-default-export>
6
+ {components.map(Component => <Component.default />)}
7
+ </div>
8
+
9
+ <div data-content-export>
10
+ {components.map(({ Content }) => <Content />)}
11
+ </div>
@@ -0,0 +1,5 @@
1
+ ---
2
+ import Test from '../components/Test.mdx';
3
+ ---
4
+
5
+ <Test />
@@ -0,0 +1,7 @@
1
+ <em><slot/></em>
2
+
3
+ <style>
4
+ em {
5
+ color: red;
6
+ }
7
+ </style>
@@ -0,0 +1 @@
1
+ <p><slot /></p>
@@ -0,0 +1 @@
1
+ <h1><slot/></h1>
@@ -0,0 +1,5 @@
1
+ import P from '../components/P.astro';
2
+ import Em from '../components/Em.astro';
3
+
4
+ <P>Render <Em>Me</Em></P>
5
+ <P><Em>Me</Em></P>
@@ -0,0 +1,13 @@
1
+ import P from '../components/P.astro';
2
+ import Em from '../components/Em.astro';
3
+ import Title from '../components/Title.astro';
4
+
5
+ export const components = { p: P, em: Em, h1: Title };
6
+
7
+ # Hello _there_
8
+
9
+ # _there_
10
+
11
+ Hello _there_
12
+
13
+ _there_
@@ -0,0 +1,38 @@
1
+ ---
2
+ const {
3
+ content = { title: "content didn't work" },
4
+ file = "file didn't work",
5
+ url = "url didn't work",
6
+ frontmatter = {
7
+ title: "frontmatter didn't work",
8
+ file: "file didn't work",
9
+ url: "url didn't work",
10
+ },
11
+ headings = [],
12
+ } = Astro.props;
13
+ ---
14
+
15
+ <!DOCTYPE html>
16
+ <html lang="en">
17
+
18
+ <head>
19
+ <meta charset="UTF-8">
20
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
21
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
22
+ </head>
23
+
24
+ <body>
25
+ <p data-content-title>{content.title}</p>
26
+ <p data-frontmatter-title>{frontmatter.title}</p>
27
+ <p data-frontmatter-file>{frontmatter.file}</p>
28
+ <p data-frontmatter-url>{frontmatter.url}</p>
29
+ <p data-file>{frontmatter.file}</p>
30
+ <p data-url>{frontmatter.url}</p>
31
+ <p data-layout-rendered>Layout rendered!</p>
32
+ <ul data-headings>
33
+ {headings.map(heading => <li>{heading.slug}</li>)}
34
+ </ul>
35
+ <slot />
36
+ </body>
37
+
38
+ </html>
@@ -0,0 +1,9 @@
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?.frontmatter?.title),
7
+ })
8
+ }
9
+ }
@@ -0,0 +1,10 @@
1
+ ---
2
+ title: 'Using YAML frontmatter'
3
+ layout: '../layouts/Base.astro'
4
+ illThrowIfIDontExist: "Oh no, that's scary!"
5
+ ---
6
+
7
+ {frontmatter.illThrowIfIDontExist}
8
+
9
+ > Note: newline intentionally missing from the end of this file.
10
+ > Useful since that can be the source of bugs in our compile step.
@@ -0,0 +1,7 @@
1
+ ---
2
+ layout: '../layouts/Base.astro'
3
+ ---
4
+
5
+ ## Section 1
6
+
7
+ ## Section 2
@@ -0,0 +1,12 @@
1
+ import { defineConfig } from 'astro/config';
2
+ import mdx from '@astrojs/mdx';
3
+ import { rehypeReadingTime, remarkTitle } from './src/markdown-plugins.mjs';
4
+
5
+ // https://astro.build/config
6
+ export default defineConfig({
7
+ site: 'https://astro.build/',
8
+ integrations: [mdx({
9
+ remarkPlugins: [remarkTitle],
10
+ rehypePlugins: [rehypeReadingTime],
11
+ })],
12
+ });
@@ -0,0 +1,17 @@
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
@@ -0,0 +1,12 @@
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
+ }
@@ -0,0 +1,17 @@
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>
@@ -0,0 +1,20 @@
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
+ }
@@ -0,0 +1,6 @@
1
+ export async function get() {
2
+ const docs = await import.meta.glob('./*.mdx', { eager: true });
3
+ return {
4
+ body: JSON.stringify(Object.values(docs).map(doc => doc.frontmatter)),
5
+ }
6
+ }
@@ -0,0 +1,7 @@
1
+ ---
2
+ layout: '../layouts/Base.astro'
3
+ ---
4
+
5
+ # Page 1
6
+
7
+ Look at that!
@@ -0,0 +1,23 @@
1
+ ---
2
+ layout: '../layouts/Base.astro'
3
+ ---
4
+
5
+ # Page 2
6
+
7
+ ## Table of contents
8
+
9
+ ## Section 1
10
+
11
+ Some text!
12
+
13
+ ### Subsection 1
14
+
15
+ Some subsection test!
16
+
17
+ ### Subsection 2
18
+
19
+ Oh cool, more text!
20
+
21
+ ## Section 2
22
+
23
+ More content
@@ -0,0 +1,7 @@
1
+ ---
2
+ title: 'Overridden title'
3
+ injectedReadingTime:
4
+ text: '1000 min read'
5
+ ---
6
+
7
+ # Working!
@@ -0,0 +1,11 @@
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
+ }
@@ -0,0 +1,8 @@
1
+ export const h2Title = "Section 1"
2
+ export const h3Title = "Subsection 1"
3
+
4
+ # Heading test with JSX expressions
5
+
6
+ ## {h2Title}
7
+
8
+ ### {h3Title}
@@ -0,0 +1,9 @@
1
+ # Heading test
2
+
3
+ ## Section 1
4
+
5
+ ### Subsection 1
6
+
7
+ ### Subsection 2
8
+
9
+ ## Section 2
@@ -0,0 +1,5 @@
1
+ ---
2
+ one: hello
3
+ slug: one
4
+ ---
5
+ First mdx file
@@ -0,0 +1,34 @@
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>
@@ -0,0 +1,6 @@
1
+ import mdx from '@astrojs/mdx';
2
+ import react from '@astrojs/react';
3
+
4
+ export default {
5
+ integrations: [react(), mdx()]
6
+ }
@@ -0,0 +1,17 @@
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
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "@test/mdx-namespace",
3
+ "dependencies": {
4
+ "@astrojs/mdx": "workspace:*",
5
+ "@astrojs/react": "workspace:*",
6
+ "astro": "workspace:*",
7
+ "react": "^18.2.0",
8
+ "react-dom": "^18.1.0"
9
+ }
10
+ }
@@ -0,0 +1,6 @@
1
+ const Component = () => {
2
+ return <p id="component">Hello world</p>;
3
+ };
4
+ export const ns = {
5
+ Component
6
+ }
@@ -0,0 +1,3 @@
1
+ import * as mod from '../components/Component.jsx';
2
+
3
+ <mod.ns.Component client:load />
@@ -0,0 +1,3 @@
1
+ import { ns } from '../components/Component.jsx';
2
+
3
+ <ns.Component client:load />
@@ -0,0 +1,5 @@
1
+ import mdx from '@astrojs/mdx';
2
+
3
+ export default {
4
+ integrations: [mdx()]
5
+ }
@@ -0,0 +1,17 @@
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
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "@test/mdx-page",
3
+ "dependencies": {
4
+ "@astrojs/mdx": "workspace:*",
5
+ "astro": "workspace:*",
6
+ "react": "^18.2.0",
7
+ "react-dom": "^18.2.0"
8
+ }
9
+ }
@@ -0,0 +1,3 @@
1
+ import '../styles.css'
2
+
3
+ # Hello page!
@@ -0,0 +1,3 @@
1
+ p {
2
+ color: red;
3
+ }
@@ -0,0 +1,19 @@
1
+ # TOC test
2
+
3
+ ## Table of contents
4
+
5
+ ## Section 1
6
+
7
+ Some text!
8
+
9
+ ### Subsection 1
10
+
11
+ Some subsection test!
12
+
13
+ ### Subsection 2
14
+
15
+ Oh cool, more text!
16
+
17
+ ## Section 2
18
+
19
+ And section 2, with a hyperlink to check GFM is preserved: https://handle-me-gfm.com
@@ -0,0 +1,6 @@
1
+ import mdx from '@astrojs/mdx';
2
+ import react from '@astrojs/react';
3
+
4
+ export default {
5
+ integrations: [react(), mdx()]
6
+ }
@@ -0,0 +1,17 @@
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
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "@test/mdx-plus-react",
3
+ "dependencies": {
4
+ "@astrojs/mdx": "workspace:*",
5
+ "@astrojs/react": "workspace:*",
6
+ "astro": "workspace:*",
7
+ "react": "^18.2.0",
8
+ "react-dom": "^18.2.0"
9
+ }
10
+ }
@@ -0,0 +1,5 @@
1
+ const Component = () => {
2
+ return <p>Hello world</p>;
3
+ };
4
+
5
+ export default Component;
@@ -0,0 +1,11 @@
1
+ ---
2
+ import Component from "../components/Component.jsx";
3
+ ---
4
+ <html>
5
+ <head>
6
+ <title>Testing</title>
7
+ </head>
8
+ <body>
9
+ <Component />
10
+ </body>
11
+ </html>
@@ -0,0 +1,9 @@
1
+ # Syntax highlighting
2
+
3
+ ```astro
4
+ ---
5
+ const handlesAstroSyntax = true
6
+ ---
7
+
8
+ <h1>{handlesAstroSyntax}</h1>
9
+ ```
@@ -0,0 +1,9 @@
1
+ export async function get() {
2
+ const mdxPages = await import.meta.glob('./*.mdx', { eager: true });
3
+
4
+ return {
5
+ body: JSON.stringify({
6
+ urls: Object.values(mdxPages ?? {}).map(v => v?.url),
7
+ })
8
+ }
9
+ }
@@ -0,0 +1 @@
1
+ # I'm a page with a url of "/test-1!"
@@ -0,0 +1 @@
1
+ # I'm a page with a url of "/test-2!"
@@ -0,0 +1,3 @@
1
+ export const url = '/AH!'
2
+
3
+ # I'm a test with a url override!
@@ -0,0 +1,9 @@
1
+ import mdx from '@astrojs/mdx';
2
+
3
+ export default {
4
+ site: 'https://mdx-is-neat.com/',
5
+ markdown: {
6
+ syntaxHighlight: false,
7
+ },
8
+ integrations: [mdx()],
9
+ }
@@ -0,0 +1,17 @@
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
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "@test/mdx-env-variables",
3
+ "dependencies": {
4
+ "astro": "workspace:*",
5
+ "@astrojs/mdx": "workspace:*"
6
+ }
7
+ }
@@ -0,0 +1,7 @@
1
+ import { frontmatter } from './vite-env-vars.mdx';
2
+
3
+ export function get() {
4
+ return {
5
+ body: JSON.stringify(frontmatter),
6
+ }
7
+ }
@@ -0,0 +1,38 @@
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>