@astrojs/mdx 0.18.3 → 0.19.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/.turbo/turbo-build.log +2 -2
- package/CHANGELOG.md +17 -0
- package/dist/index.js +5 -2
- package/dist/plugins.js +5 -2
- package/dist/remark-images-to-component.d.ts +2 -0
- package/dist/remark-images-to-component.js +84 -0
- package/package.json +6 -5
- package/src/index.ts +5 -1
- package/src/plugins.ts +5 -2
- package/src/remark-images-to-component.ts +98 -0
- package/test/fixtures/css-head-mdx/node_modules/.bin/astro +2 -2
- package/test/fixtures/mdx-frontmatter-injection/node_modules/.bin/astro +2 -2
- package/test/fixtures/mdx-images/astro.config.ts +8 -0
- package/test/fixtures/mdx-images/node_modules/.bin/astro +17 -0
- package/test/fixtures/mdx-images/package.json +9 -0
- package/test/fixtures/mdx-images/src/assets/houston in space.webp +0 -0
- package/test/fixtures/mdx-images/src/assets/houston.webp +0 -0
- package/test/fixtures/mdx-images/src/pages/index.mdx +11 -0
- package/test/fixtures/mdx-infinite-loop/node_modules/.bin/astro +2 -2
- package/test/fixtures/mdx-namespace/node_modules/.bin/astro +2 -2
- package/test/fixtures/mdx-page/node_modules/.bin/astro +2 -2
- package/test/fixtures/mdx-plus-react/node_modules/.bin/astro +2 -2
- package/test/fixtures/mdx-vite-env-vars/node_modules/.bin/astro +2 -2
- package/test/mdx-images.test.js +40 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
[34m@astrojs/mdx:build: [0mcache hit, replaying output [
|
|
1
|
+
[34m@astrojs/mdx:build: [0mcache hit, replaying output [2m8f7758540a171891[0m
|
|
2
2
|
[34m@astrojs/mdx:build: [0m
|
|
3
|
-
[34m@astrojs/mdx:build: [0m> @astrojs/mdx@0.
|
|
3
|
+
[34m@astrojs/mdx:build: [0m> @astrojs/mdx@0.19.0 build /home/runner/work/astro/astro/packages/integrations/mdx
|
|
4
4
|
[34m@astrojs/mdx:build: [0m> astro-scripts build "src/**/*.ts" && tsc
|
|
5
5
|
[34m@astrojs/mdx:build: [0m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @astrojs/mdx
|
|
2
2
|
|
|
3
|
+
## 0.19.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#6824](https://github.com/withastro/astro/pull/6824) [`2511d58d5`](https://github.com/withastro/astro/commit/2511d58d586af080a78e5ef8a63020b3e17770db) Thanks [@Princesseuh](https://github.com/Princesseuh)! - Add support for using optimized and relative images in MDX files with `experimental.assets`
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [[`2511d58d5`](https://github.com/withastro/astro/commit/2511d58d586af080a78e5ef8a63020b3e17770db)]:
|
|
12
|
+
- @astrojs/markdown-remark@2.1.4
|
|
13
|
+
|
|
14
|
+
## 0.18.4
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- [#6817](https://github.com/withastro/astro/pull/6817) [`f882bc163`](https://github.com/withastro/astro/commit/f882bc1636d5ce1c3b8faae47df36b4dc758045a) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Fix sourcemap warnings when using Content Collections and MDX with the `vite.build.sourcemap` option
|
|
19
|
+
|
|
3
20
|
## 0.18.3
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,7 @@ import mdxPlugin from "@mdx-js/rollup";
|
|
|
5
5
|
import { parse as parseESM } from "es-module-lexer";
|
|
6
6
|
import fs from "node:fs/promises";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
|
+
import { SourceMapGenerator } from "source-map";
|
|
8
9
|
import { VFile } from "vfile";
|
|
9
10
|
import { getRehypePlugins, getRemarkPlugins, recmaInjectImportMetaEnvPlugin } from "./plugins.js";
|
|
10
11
|
import { getFileInfo, ignoreStringPlugins, parseFrontmatter } from "./utils.js";
|
|
@@ -64,6 +65,7 @@ function mdx(partialMdxOptions = {}) {
|
|
|
64
65
|
// Override transform to alter code before MDX compilation
|
|
65
66
|
// ex. inject layouts
|
|
66
67
|
async transform(_, id) {
|
|
68
|
+
var _a;
|
|
67
69
|
if (!id.endsWith("mdx"))
|
|
68
70
|
return;
|
|
69
71
|
const { fileId } = getFileInfo(id, config);
|
|
@@ -80,7 +82,8 @@ function mdx(partialMdxOptions = {}) {
|
|
|
80
82
|
recmaPlugins: [
|
|
81
83
|
...mdxPluginOpts.recmaPlugins ?? [],
|
|
82
84
|
() => recmaInjectImportMetaEnvPlugin({ importMetaEnv })
|
|
83
|
-
]
|
|
85
|
+
],
|
|
86
|
+
SourceMapGenerator: ((_a = config.vite.build) == null ? void 0 : _a.sourcemap) ? SourceMapGenerator : void 0
|
|
84
87
|
});
|
|
85
88
|
return {
|
|
86
89
|
code: escapeViteEnvReferences(String(compiled.value)),
|
|
@@ -130,7 +133,7 @@ if (import.meta.hot) {
|
|
|
130
133
|
import.meta.hot.decline();
|
|
131
134
|
}`;
|
|
132
135
|
}
|
|
133
|
-
return escapeViteEnvReferences(code);
|
|
136
|
+
return { code: escapeViteEnvReferences(code), map: null };
|
|
134
137
|
}
|
|
135
138
|
}
|
|
136
139
|
]
|
package/dist/plugins.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { rehypeHeadingIds } from "@astrojs/markdown-remark";
|
|
1
|
+
import { rehypeHeadingIds, remarkCollectImages } from "@astrojs/markdown-remark";
|
|
2
2
|
import {
|
|
3
3
|
InvalidAstroDataError,
|
|
4
4
|
safelyGetAstroData
|
|
@@ -10,6 +10,7 @@ import remarkGfm from "remark-gfm";
|
|
|
10
10
|
import remarkSmartypants from "remark-smartypants";
|
|
11
11
|
import { rehypeInjectHeadingsExport } from "./rehype-collect-headings.js";
|
|
12
12
|
import rehypeMetaString from "./rehype-meta-string.js";
|
|
13
|
+
import { remarkImageToComponent } from "./remark-images-to-component.js";
|
|
13
14
|
import remarkPrism from "./remark-prism.js";
|
|
14
15
|
import remarkShiki from "./remark-shiki.js";
|
|
15
16
|
import { jsToTreeNode } from "./utils.js";
|
|
@@ -77,7 +78,9 @@ function rehypeApplyFrontmatterExport() {
|
|
|
77
78
|
};
|
|
78
79
|
}
|
|
79
80
|
async function getRemarkPlugins(mdxOptions, config) {
|
|
80
|
-
let remarkPlugins = [
|
|
81
|
+
let remarkPlugins = [
|
|
82
|
+
...config.experimental.assets ? [remarkCollectImages, remarkImageToComponent] : []
|
|
83
|
+
];
|
|
81
84
|
if (!isPerformanceBenchmark) {
|
|
82
85
|
if (mdxOptions.gfm) {
|
|
83
86
|
remarkPlugins.push(remarkGfm);
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { visit } from "unist-util-visit";
|
|
2
|
+
import { jsToTreeNode } from "./utils.js";
|
|
3
|
+
function remarkImageToComponent() {
|
|
4
|
+
return function(tree, file) {
|
|
5
|
+
if (!file.data.imagePaths)
|
|
6
|
+
return;
|
|
7
|
+
const importsStatements = [];
|
|
8
|
+
const importedImages = /* @__PURE__ */ new Map();
|
|
9
|
+
visit(tree, "image", (node, index, parent) => {
|
|
10
|
+
var _a;
|
|
11
|
+
if ((_a = file.data.imagePaths) == null ? void 0 : _a.has(node.url)) {
|
|
12
|
+
let importName = importedImages.get(node.url);
|
|
13
|
+
if (!importName) {
|
|
14
|
+
importName = `__${importedImages.size}_${node.url.replace(/\W/g, "_")}__`;
|
|
15
|
+
importsStatements.push({
|
|
16
|
+
type: "mdxjsEsm",
|
|
17
|
+
value: "",
|
|
18
|
+
data: {
|
|
19
|
+
estree: {
|
|
20
|
+
type: "Program",
|
|
21
|
+
sourceType: "module",
|
|
22
|
+
body: [
|
|
23
|
+
{
|
|
24
|
+
type: "ImportDeclaration",
|
|
25
|
+
source: { type: "Literal", value: node.url, raw: JSON.stringify(node.url) },
|
|
26
|
+
specifiers: [
|
|
27
|
+
{
|
|
28
|
+
type: "ImportDefaultSpecifier",
|
|
29
|
+
local: { type: "Identifier", name: importName }
|
|
30
|
+
}
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
importedImages.set(node.url, importName);
|
|
38
|
+
}
|
|
39
|
+
const componentElement = {
|
|
40
|
+
name: "__AstroImage__",
|
|
41
|
+
type: "mdxJsxFlowElement",
|
|
42
|
+
attributes: [
|
|
43
|
+
{
|
|
44
|
+
name: "src",
|
|
45
|
+
type: "mdxJsxAttribute",
|
|
46
|
+
value: {
|
|
47
|
+
type: "mdxJsxAttributeValueExpression",
|
|
48
|
+
value: importName,
|
|
49
|
+
data: {
|
|
50
|
+
estree: {
|
|
51
|
+
type: "Program",
|
|
52
|
+
sourceType: "module",
|
|
53
|
+
comments: [],
|
|
54
|
+
body: [
|
|
55
|
+
{
|
|
56
|
+
type: "ExpressionStatement",
|
|
57
|
+
expression: { type: "Identifier", name: importName }
|
|
58
|
+
}
|
|
59
|
+
]
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
{ name: "alt", type: "mdxJsxAttribute", value: node.alt || "" }
|
|
65
|
+
],
|
|
66
|
+
children: []
|
|
67
|
+
};
|
|
68
|
+
if (node.title) {
|
|
69
|
+
componentElement.attributes.push({
|
|
70
|
+
type: "mdxJsxAttribute",
|
|
71
|
+
name: "title",
|
|
72
|
+
value: node.title
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
parent.children.splice(index, 1, componentElement);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
tree.children.unshift(...importsStatements);
|
|
79
|
+
tree.children.unshift(jsToTreeNode(`import { Image as __AstroImage__ } from "astro:assets";`));
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
export {
|
|
83
|
+
remarkImageToComponent
|
|
84
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/mdx",
|
|
3
3
|
"description": "Add support for MDX pages in your Astro site",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.19.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"author": "withastro",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"./package.json": "./package.json"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@astrojs/markdown-remark": "^2.1.
|
|
26
|
+
"@astrojs/markdown-remark": "^2.1.4",
|
|
27
27
|
"@astrojs/prism": "^2.1.1",
|
|
28
28
|
"@mdx-js/mdx": "^2.3.0",
|
|
29
29
|
"@mdx-js/rollup": "^2.3.0",
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
"remark-gfm": "^3.0.1",
|
|
39
39
|
"remark-smartypants": "^2.0.0",
|
|
40
40
|
"shiki": "^0.11.1",
|
|
41
|
+
"source-map": "^0.7.4",
|
|
41
42
|
"unist-util-visit": "^4.1.0",
|
|
42
43
|
"vfile": "^5.3.2"
|
|
43
44
|
},
|
|
@@ -48,8 +49,6 @@
|
|
|
48
49
|
"@types/mdast": "^3.0.10",
|
|
49
50
|
"@types/mocha": "^9.1.1",
|
|
50
51
|
"@types/yargs-parser": "^21.0.0",
|
|
51
|
-
"astro": "2.2.1",
|
|
52
|
-
"astro-scripts": "0.0.14",
|
|
53
52
|
"chai": "^4.3.6",
|
|
54
53
|
"cheerio": "^1.0.0-rc.11",
|
|
55
54
|
"linkedom": "^0.14.12",
|
|
@@ -63,7 +62,9 @@
|
|
|
63
62
|
"remark-rehype": "^10.1.0",
|
|
64
63
|
"remark-shiki-twoslash": "^3.1.0",
|
|
65
64
|
"remark-toc": "^8.0.1",
|
|
66
|
-
"vite": "^4.2.1"
|
|
65
|
+
"vite": "^4.2.1",
|
|
66
|
+
"astro": "2.3.0",
|
|
67
|
+
"astro-scripts": "0.0.14"
|
|
67
68
|
},
|
|
68
69
|
"engines": {
|
|
69
70
|
"node": ">=16.12.0"
|
package/src/index.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { parse as parseESM } from 'es-module-lexer';
|
|
|
8
8
|
import fs from 'node:fs/promises';
|
|
9
9
|
import { fileURLToPath } from 'node:url';
|
|
10
10
|
import type { Options as RemarkRehypeOptions } from 'remark-rehype';
|
|
11
|
+
import { SourceMapGenerator } from 'source-map';
|
|
11
12
|
import { VFile } from 'vfile';
|
|
12
13
|
import type { Plugin as VitePlugin } from 'vite';
|
|
13
14
|
import { getRehypePlugins, getRemarkPlugins, recmaInjectImportMetaEnvPlugin } from './plugins.js';
|
|
@@ -113,6 +114,9 @@ export default function mdx(partialMdxOptions: Partial<MdxOptions> = {}): AstroI
|
|
|
113
114
|
...(mdxPluginOpts.recmaPlugins ?? []),
|
|
114
115
|
() => recmaInjectImportMetaEnvPlugin({ importMetaEnv }),
|
|
115
116
|
],
|
|
117
|
+
SourceMapGenerator: config.vite.build?.sourcemap
|
|
118
|
+
? SourceMapGenerator
|
|
119
|
+
: undefined,
|
|
116
120
|
});
|
|
117
121
|
|
|
118
122
|
return {
|
|
@@ -168,7 +172,7 @@ export default function mdx(partialMdxOptions: Partial<MdxOptions> = {}): AstroI
|
|
|
168
172
|
import.meta.hot.decline();
|
|
169
173
|
}`;
|
|
170
174
|
}
|
|
171
|
-
return escapeViteEnvReferences(code);
|
|
175
|
+
return { code: escapeViteEnvReferences(code), map: null };
|
|
172
176
|
},
|
|
173
177
|
},
|
|
174
178
|
] as VitePlugin[],
|
package/src/plugins.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { rehypeHeadingIds } from '@astrojs/markdown-remark';
|
|
1
|
+
import { rehypeHeadingIds, remarkCollectImages } from '@astrojs/markdown-remark';
|
|
2
2
|
import {
|
|
3
3
|
InvalidAstroDataError,
|
|
4
4
|
safelyGetAstroData,
|
|
@@ -16,6 +16,7 @@ import type { VFile } from 'vfile';
|
|
|
16
16
|
import type { MdxOptions } from './index.js';
|
|
17
17
|
import { rehypeInjectHeadingsExport } from './rehype-collect-headings.js';
|
|
18
18
|
import rehypeMetaString from './rehype-meta-string.js';
|
|
19
|
+
import { remarkImageToComponent } from './remark-images-to-component.js';
|
|
19
20
|
import remarkPrism from './remark-prism.js';
|
|
20
21
|
import remarkShiki from './remark-shiki.js';
|
|
21
22
|
import { jsToTreeNode } from './utils.js';
|
|
@@ -99,7 +100,9 @@ export async function getRemarkPlugins(
|
|
|
99
100
|
mdxOptions: MdxOptions,
|
|
100
101
|
config: AstroConfig
|
|
101
102
|
): Promise<MdxRollupPluginOptions['remarkPlugins']> {
|
|
102
|
-
let remarkPlugins: PluggableList = [
|
|
103
|
+
let remarkPlugins: PluggableList = [
|
|
104
|
+
...(config.experimental.assets ? [remarkCollectImages, remarkImageToComponent] : []),
|
|
105
|
+
];
|
|
103
106
|
|
|
104
107
|
if (!isPerformanceBenchmark) {
|
|
105
108
|
if (mdxOptions.gfm) {
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { MarkdownVFile } from '@astrojs/markdown-remark';
|
|
2
|
+
import { type Image, type Parent } from 'mdast';
|
|
3
|
+
import type { MdxjsEsm, MdxJsxFlowElement } from 'mdast-util-mdx';
|
|
4
|
+
import { visit } from 'unist-util-visit';
|
|
5
|
+
import { jsToTreeNode } from './utils.js';
|
|
6
|
+
|
|
7
|
+
export function remarkImageToComponent() {
|
|
8
|
+
return function (tree: any, file: MarkdownVFile) {
|
|
9
|
+
if (!file.data.imagePaths) return;
|
|
10
|
+
|
|
11
|
+
const importsStatements: MdxjsEsm[] = [];
|
|
12
|
+
const importedImages = new Map<string, string>();
|
|
13
|
+
|
|
14
|
+
visit(tree, 'image', (node: Image, index: number | null, parent: Parent | null) => {
|
|
15
|
+
// Use the imagePaths set from the remark-collect-images so we don't have to duplicate the logic for
|
|
16
|
+
// checking if an image should be imported or not
|
|
17
|
+
if (file.data.imagePaths?.has(node.url)) {
|
|
18
|
+
let importName = importedImages.get(node.url);
|
|
19
|
+
|
|
20
|
+
// If we haven't already imported this image, add an import statement
|
|
21
|
+
if (!importName) {
|
|
22
|
+
importName = `__${importedImages.size}_${node.url.replace(/\W/g, '_')}__`;
|
|
23
|
+
|
|
24
|
+
importsStatements.push({
|
|
25
|
+
type: 'mdxjsEsm',
|
|
26
|
+
value: '',
|
|
27
|
+
data: {
|
|
28
|
+
estree: {
|
|
29
|
+
type: 'Program',
|
|
30
|
+
sourceType: 'module',
|
|
31
|
+
body: [
|
|
32
|
+
{
|
|
33
|
+
type: 'ImportDeclaration',
|
|
34
|
+
source: { type: 'Literal', value: node.url, raw: JSON.stringify(node.url) },
|
|
35
|
+
specifiers: [
|
|
36
|
+
{
|
|
37
|
+
type: 'ImportDefaultSpecifier',
|
|
38
|
+
local: { type: 'Identifier', name: importName },
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
importedImages.set(node.url, importName);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Build a component that's equivalent to <Image src={importName} alt={node.alt} title={node.title} />
|
|
50
|
+
const componentElement: MdxJsxFlowElement = {
|
|
51
|
+
name: '__AstroImage__',
|
|
52
|
+
type: 'mdxJsxFlowElement',
|
|
53
|
+
attributes: [
|
|
54
|
+
{
|
|
55
|
+
name: 'src',
|
|
56
|
+
type: 'mdxJsxAttribute',
|
|
57
|
+
value: {
|
|
58
|
+
type: 'mdxJsxAttributeValueExpression',
|
|
59
|
+
value: importName,
|
|
60
|
+
data: {
|
|
61
|
+
estree: {
|
|
62
|
+
type: 'Program',
|
|
63
|
+
sourceType: 'module',
|
|
64
|
+
comments: [],
|
|
65
|
+
body: [
|
|
66
|
+
{
|
|
67
|
+
type: 'ExpressionStatement',
|
|
68
|
+
expression: { type: 'Identifier', name: importName },
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
{ name: 'alt', type: 'mdxJsxAttribute', value: node.alt || '' },
|
|
76
|
+
],
|
|
77
|
+
children: [],
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
if (node.title) {
|
|
81
|
+
componentElement.attributes.push({
|
|
82
|
+
type: 'mdxJsxAttribute',
|
|
83
|
+
name: 'title',
|
|
84
|
+
value: node.title,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
parent!.children.splice(index!, 1, componentElement);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// Add all the import statements to the top of the file for the images
|
|
93
|
+
tree.children.unshift(...importsStatements);
|
|
94
|
+
|
|
95
|
+
// Add an import statement for the Astro Image component, we rename it to avoid conflicts
|
|
96
|
+
tree.children.unshift(jsToTreeNode(`import { Image as __AstroImage__ } from "astro:assets";`));
|
|
97
|
+
};
|
|
98
|
+
}
|
|
@@ -6,9 +6,9 @@ case `uname` in
|
|
|
6
6
|
esac
|
|
7
7
|
|
|
8
8
|
if [ -z "$NODE_PATH" ]; then
|
|
9
|
-
export NODE_PATH="/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
|
|
9
|
+
export NODE_PATH="/home/runner/work/astro/astro/packages/astro/node_modules:/home/runner/work/astro/astro/packages/node_modules:/home/runner/work/astro/astro/node_modules:/home/runner/work/astro/node_modules:/home/runner/work/node_modules:/home/runner/node_modules:/home/node_modules:/node_modules:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
|
|
10
10
|
else
|
|
11
|
-
export NODE_PATH="
|
|
11
|
+
export NODE_PATH="/home/runner/work/astro/astro/packages/astro/node_modules:/home/runner/work/astro/astro/packages/node_modules:/home/runner/work/astro/astro/node_modules:/home/runner/work/astro/node_modules:/home/runner/work/node_modules:/home/runner/node_modules:/home/node_modules:/node_modules:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules:$NODE_PATH"
|
|
12
12
|
fi
|
|
13
13
|
if [ -x "$basedir/node" ]; then
|
|
14
14
|
exec "$basedir/node" "$basedir/../../../../../../../astro/astro.js" "$@"
|
|
@@ -6,9 +6,9 @@ case `uname` in
|
|
|
6
6
|
esac
|
|
7
7
|
|
|
8
8
|
if [ -z "$NODE_PATH" ]; then
|
|
9
|
-
export NODE_PATH="/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
|
|
9
|
+
export NODE_PATH="/home/runner/work/astro/astro/packages/astro/node_modules:/home/runner/work/astro/astro/packages/node_modules:/home/runner/work/astro/astro/node_modules:/home/runner/work/astro/node_modules:/home/runner/work/node_modules:/home/runner/node_modules:/home/node_modules:/node_modules:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
|
|
10
10
|
else
|
|
11
|
-
export NODE_PATH="
|
|
11
|
+
export NODE_PATH="/home/runner/work/astro/astro/packages/astro/node_modules:/home/runner/work/astro/astro/packages/node_modules:/home/runner/work/astro/astro/node_modules:/home/runner/work/astro/node_modules:/home/runner/work/node_modules:/home/runner/node_modules:/home/node_modules:/node_modules:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules:$NODE_PATH"
|
|
12
12
|
fi
|
|
13
13
|
if [ -x "$basedir/node" ]; then
|
|
14
14
|
exec "$basedir/node" "$basedir/../../../../../../../astro/astro.js" "$@"
|
|
@@ -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/packages/astro/node_modules:/home/runner/work/astro/astro/packages/node_modules:/home/runner/work/astro/astro/node_modules:/home/runner/work/astro/node_modules:/home/runner/work/node_modules:/home/runner/node_modules:/home/node_modules:/node_modules:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
|
|
10
|
+
else
|
|
11
|
+
export NODE_PATH="/home/runner/work/astro/astro/packages/astro/node_modules:/home/runner/work/astro/astro/packages/node_modules:/home/runner/work/astro/astro/node_modules:/home/runner/work/astro/node_modules:/home/runner/work/node_modules:/home/runner/node_modules:/home/node_modules:/node_modules:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules:$NODE_PATH"
|
|
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
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Image using a relative path:
|
|
2
|
+

|
|
3
|
+
|
|
4
|
+
Image using an aliased path:
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
Image with a title:
|
|
8
|
+

|
|
9
|
+
|
|
10
|
+
Image with spaces in the path:
|
|
11
|
+

|
|
@@ -6,9 +6,9 @@ case `uname` in
|
|
|
6
6
|
esac
|
|
7
7
|
|
|
8
8
|
if [ -z "$NODE_PATH" ]; then
|
|
9
|
-
export NODE_PATH="/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
|
|
9
|
+
export NODE_PATH="/home/runner/work/astro/astro/packages/astro/node_modules:/home/runner/work/astro/astro/packages/node_modules:/home/runner/work/astro/astro/node_modules:/home/runner/work/astro/node_modules:/home/runner/work/node_modules:/home/runner/node_modules:/home/node_modules:/node_modules:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
|
|
10
10
|
else
|
|
11
|
-
export NODE_PATH="
|
|
11
|
+
export NODE_PATH="/home/runner/work/astro/astro/packages/astro/node_modules:/home/runner/work/astro/astro/packages/node_modules:/home/runner/work/astro/astro/node_modules:/home/runner/work/astro/node_modules:/home/runner/work/node_modules:/home/runner/node_modules:/home/node_modules:/node_modules:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules:$NODE_PATH"
|
|
12
12
|
fi
|
|
13
13
|
if [ -x "$basedir/node" ]; then
|
|
14
14
|
exec "$basedir/node" "$basedir/../../../../../../../astro/astro.js" "$@"
|
|
@@ -6,9 +6,9 @@ case `uname` in
|
|
|
6
6
|
esac
|
|
7
7
|
|
|
8
8
|
if [ -z "$NODE_PATH" ]; then
|
|
9
|
-
export NODE_PATH="/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
|
|
9
|
+
export NODE_PATH="/home/runner/work/astro/astro/packages/astro/node_modules:/home/runner/work/astro/astro/packages/node_modules:/home/runner/work/astro/astro/node_modules:/home/runner/work/astro/node_modules:/home/runner/work/node_modules:/home/runner/node_modules:/home/node_modules:/node_modules:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
|
|
10
10
|
else
|
|
11
|
-
export NODE_PATH="
|
|
11
|
+
export NODE_PATH="/home/runner/work/astro/astro/packages/astro/node_modules:/home/runner/work/astro/astro/packages/node_modules:/home/runner/work/astro/astro/node_modules:/home/runner/work/astro/node_modules:/home/runner/work/node_modules:/home/runner/node_modules:/home/node_modules:/node_modules:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules:$NODE_PATH"
|
|
12
12
|
fi
|
|
13
13
|
if [ -x "$basedir/node" ]; then
|
|
14
14
|
exec "$basedir/node" "$basedir/../../../../../../../astro/astro.js" "$@"
|
|
@@ -6,9 +6,9 @@ case `uname` in
|
|
|
6
6
|
esac
|
|
7
7
|
|
|
8
8
|
if [ -z "$NODE_PATH" ]; then
|
|
9
|
-
export NODE_PATH="/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
|
|
9
|
+
export NODE_PATH="/home/runner/work/astro/astro/packages/astro/node_modules:/home/runner/work/astro/astro/packages/node_modules:/home/runner/work/astro/astro/node_modules:/home/runner/work/astro/node_modules:/home/runner/work/node_modules:/home/runner/node_modules:/home/node_modules:/node_modules:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
|
|
10
10
|
else
|
|
11
|
-
export NODE_PATH="
|
|
11
|
+
export NODE_PATH="/home/runner/work/astro/astro/packages/astro/node_modules:/home/runner/work/astro/astro/packages/node_modules:/home/runner/work/astro/astro/node_modules:/home/runner/work/astro/node_modules:/home/runner/work/node_modules:/home/runner/node_modules:/home/node_modules:/node_modules:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules:$NODE_PATH"
|
|
12
12
|
fi
|
|
13
13
|
if [ -x "$basedir/node" ]; then
|
|
14
14
|
exec "$basedir/node" "$basedir/../../../../../../../astro/astro.js" "$@"
|
|
@@ -6,9 +6,9 @@ case `uname` in
|
|
|
6
6
|
esac
|
|
7
7
|
|
|
8
8
|
if [ -z "$NODE_PATH" ]; then
|
|
9
|
-
export NODE_PATH="/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
|
|
9
|
+
export NODE_PATH="/home/runner/work/astro/astro/packages/astro/node_modules:/home/runner/work/astro/astro/packages/node_modules:/home/runner/work/astro/astro/node_modules:/home/runner/work/astro/node_modules:/home/runner/work/node_modules:/home/runner/node_modules:/home/node_modules:/node_modules:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
|
|
10
10
|
else
|
|
11
|
-
export NODE_PATH="
|
|
11
|
+
export NODE_PATH="/home/runner/work/astro/astro/packages/astro/node_modules:/home/runner/work/astro/astro/packages/node_modules:/home/runner/work/astro/astro/node_modules:/home/runner/work/astro/node_modules:/home/runner/work/node_modules:/home/runner/node_modules:/home/node_modules:/node_modules:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules:$NODE_PATH"
|
|
12
12
|
fi
|
|
13
13
|
if [ -x "$basedir/node" ]; then
|
|
14
14
|
exec "$basedir/node" "$basedir/../../../../../../../astro/astro.js" "$@"
|
|
@@ -6,9 +6,9 @@ case `uname` in
|
|
|
6
6
|
esac
|
|
7
7
|
|
|
8
8
|
if [ -z "$NODE_PATH" ]; then
|
|
9
|
-
export NODE_PATH="/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
|
|
9
|
+
export NODE_PATH="/home/runner/work/astro/astro/packages/astro/node_modules:/home/runner/work/astro/astro/packages/node_modules:/home/runner/work/astro/astro/node_modules:/home/runner/work/astro/node_modules:/home/runner/work/node_modules:/home/runner/node_modules:/home/node_modules:/node_modules:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
|
|
10
10
|
else
|
|
11
|
-
export NODE_PATH="
|
|
11
|
+
export NODE_PATH="/home/runner/work/astro/astro/packages/astro/node_modules:/home/runner/work/astro/astro/packages/node_modules:/home/runner/work/astro/astro/node_modules:/home/runner/work/astro/node_modules:/home/runner/work/node_modules:/home/runner/node_modules:/home/node_modules:/node_modules:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules:$NODE_PATH"
|
|
12
12
|
fi
|
|
13
13
|
if [ -x "$basedir/node" ]; then
|
|
14
14
|
exec "$basedir/node" "$basedir/../../../../../../../astro/astro.js" "$@"
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { expect } from 'chai';
|
|
2
|
+
import { parseHTML } from 'linkedom';
|
|
3
|
+
import { loadFixture } from '../../../astro/test/test-utils.js';
|
|
4
|
+
|
|
5
|
+
describe('MDX Page', () => {
|
|
6
|
+
let devServer;
|
|
7
|
+
let fixture;
|
|
8
|
+
|
|
9
|
+
before(async () => {
|
|
10
|
+
fixture = await loadFixture({
|
|
11
|
+
root: new URL('./fixtures/mdx-images/', import.meta.url),
|
|
12
|
+
});
|
|
13
|
+
devServer = await fixture.startDevServer();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
after(async () => {
|
|
17
|
+
await devServer.stop();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
describe('Optimized images in MDX', () => {
|
|
21
|
+
it('works', async () => {
|
|
22
|
+
const res = await fixture.fetch('/');
|
|
23
|
+
expect(res.status).to.equal(200);
|
|
24
|
+
|
|
25
|
+
const html = await res.text();
|
|
26
|
+
const { document } = parseHTML(html);
|
|
27
|
+
|
|
28
|
+
const imgs = document.getElementsByTagName('img');
|
|
29
|
+
expect(imgs.length).to.equal(4);
|
|
30
|
+
// Image using a relative path
|
|
31
|
+
expect(imgs.item(0).src.startsWith('/_image')).to.be.true;
|
|
32
|
+
// Image using an aliased path
|
|
33
|
+
expect(imgs.item(1).src.startsWith('/_image')).to.be.true;
|
|
34
|
+
// Image with title
|
|
35
|
+
expect(imgs.item(2).title).to.equal('Houston title');
|
|
36
|
+
// Image with spaces in the path
|
|
37
|
+
expect(imgs.item(3).src.startsWith('/_image')).to.be.true;
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
});
|