@astrojs/markdoc 0.0.4 → 0.1.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 +5 -5
- package/CHANGELOG.md +66 -0
- package/README.md +110 -146
- package/components/Renderer.astro +8 -11
- package/components/TreeNode.ts +6 -15
- package/dist/config.d.ts +2 -0
- package/dist/config.js +6 -0
- package/dist/default-config.d.ts +5 -0
- package/dist/default-config.js +13 -0
- package/dist/experimental-assets-config.d.ts +2 -0
- package/dist/experimental-assets-config.js +25 -0
- package/dist/index.d.ts +1 -2
- package/dist/index.js +74 -53
- package/dist/load-config.d.ts +14 -0
- package/dist/load-config.js +82 -0
- package/dist/utils.d.ts +1 -11
- package/dist/utils.js +7 -41
- package/package.json +11 -2
- package/src/config.ts +5 -0
- package/src/default-config.ts +18 -0
- package/src/experimental-assets-config.ts +29 -0
- package/src/index.ts +116 -59
- package/src/load-config.ts +102 -0
- package/src/utils.ts +5 -54
- package/template/content-module-types.d.ts +1 -3
- package/test/content-collections.test.js +24 -172
- package/test/fixtures/content-collections/package.json +0 -4
- package/test/fixtures/content-collections/src/content/blog/post-1.mdoc +7 -0
- package/test/fixtures/content-collections/src/content/blog/post-2.mdoc +7 -0
- package/test/fixtures/content-collections/src/content/blog/post-3.mdoc +7 -0
- package/test/fixtures/content-collections/src/pages/entry.json.js +1 -1
- package/test/fixtures/image-assets/astro.config.mjs +10 -0
- package/test/fixtures/image-assets/node_modules/.bin/astro +17 -0
- package/test/fixtures/image-assets/package.json +9 -0
- package/test/fixtures/image-assets/src/assets/alias/cityscape.jpg +0 -0
- package/test/fixtures/image-assets/src/assets/relative/oar.jpg +0 -0
- package/test/fixtures/image-assets/src/content/docs/intro.mdoc +7 -0
- package/test/fixtures/image-assets/src/pages/index.astro +19 -0
- package/test/fixtures/image-assets/src/public/favicon.svg +9 -0
- package/test/fixtures/render-simple/astro.config.mjs +7 -0
- package/test/fixtures/render-simple/node_modules/.bin/astro +17 -0
- package/test/fixtures/render-simple/package.json +9 -0
- package/test/fixtures/{content-collections/src/pages/content-simple.astro → render-simple/src/pages/index.astro} +2 -1
- package/test/fixtures/render-with-components/astro.config.mjs +7 -0
- package/test/fixtures/render-with-components/markdoc.config.mjs +28 -0
- package/test/fixtures/render-with-components/node_modules/.bin/astro +17 -0
- package/test/fixtures/render-with-components/package.json +12 -0
- package/test/fixtures/{content-collections/src/pages/content-with-components.astro → render-with-components/src/pages/index.astro} +2 -6
- package/test/fixtures/render-with-config/astro.config.mjs +7 -0
- package/test/fixtures/render-with-config/markdoc.config.mjs +15 -0
- package/test/fixtures/render-with-config/node_modules/.bin/astro +17 -0
- package/test/fixtures/render-with-config/package.json +9 -0
- package/test/fixtures/{content-collections → render-with-config}/src/content/blog/with-config.mdoc +4 -0
- package/test/fixtures/{content-collections/src/pages/content-with-config.astro → render-with-config/src/pages/index.astro} +2 -2
- package/test/image-assets.test.js +76 -0
- package/test/render.test.js +124 -0
- /package/test/fixtures/{content-collections → render-simple}/src/content/blog/simple.mdoc +0 -0
- /package/test/fixtures/{content-collections → render-with-components}/src/components/Code.astro +0 -0
- /package/test/fixtures/{content-collections → render-with-components}/src/components/CustomMarquee.astro +0 -0
- /package/test/fixtures/{content-collections → render-with-components}/src/content/blog/with-components.mdoc +0 -0
|
@@ -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
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
---
|
|
2
2
|
import { getEntryBySlug } from "astro:content";
|
|
3
|
-
import Code from '../components/Code.astro';
|
|
4
|
-
import CustomMarquee from '../components/CustomMarquee.astro';
|
|
5
3
|
|
|
6
4
|
const post = await getEntryBySlug('blog', 'with-components');
|
|
7
5
|
const { Content } = await post.render();
|
|
@@ -13,11 +11,9 @@ const { Content } = await post.render();
|
|
|
13
11
|
<meta charset="UTF-8">
|
|
14
12
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
15
13
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
16
|
-
<title>Content
|
|
14
|
+
<title>Content</title>
|
|
17
15
|
</head>
|
|
18
16
|
<body>
|
|
19
|
-
<Content
|
|
20
|
-
components={{ CustomMarquee, Code }}
|
|
21
|
-
/>
|
|
17
|
+
<Content />
|
|
22
18
|
</body>
|
|
23
19
|
</html>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { defineMarkdocConfig } from '@astrojs/markdoc/config';
|
|
2
|
+
|
|
3
|
+
export default defineMarkdocConfig({
|
|
4
|
+
variables: {
|
|
5
|
+
countries: ['ES', 'JP'],
|
|
6
|
+
},
|
|
7
|
+
functions: {
|
|
8
|
+
includes: {
|
|
9
|
+
transform(parameters) {
|
|
10
|
+
const [array, value] = Object.values(parameters);
|
|
11
|
+
return Array.isArray(array) ? array.includes(value) : false;
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
})
|
|
@@ -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
|
|
@@ -11,9 +11,9 @@ const { Content } = await post.render();
|
|
|
11
11
|
<meta charset="UTF-8">
|
|
12
12
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
13
13
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
14
|
-
<title>Content
|
|
14
|
+
<title>Content</title>
|
|
15
15
|
</head>
|
|
16
16
|
<body>
|
|
17
|
-
<Content />
|
|
17
|
+
<Content runtimeVariable="working!" />
|
|
18
18
|
</body>
|
|
19
19
|
</html>
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { parseHTML } from 'linkedom';
|
|
2
|
+
import { expect } from 'chai';
|
|
3
|
+
import { loadFixture } from '../../../astro/test/test-utils.js';
|
|
4
|
+
|
|
5
|
+
const root = new URL('./fixtures/image-assets/', import.meta.url);
|
|
6
|
+
|
|
7
|
+
describe('Markdoc - Image assets', () => {
|
|
8
|
+
let baseFixture;
|
|
9
|
+
|
|
10
|
+
before(async () => {
|
|
11
|
+
baseFixture = await loadFixture({
|
|
12
|
+
root,
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
describe('dev', () => {
|
|
17
|
+
let devServer;
|
|
18
|
+
|
|
19
|
+
before(async () => {
|
|
20
|
+
devServer = await baseFixture.startDevServer();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
after(async () => {
|
|
24
|
+
await devServer.stop();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('uses public/ image paths unchanged', async () => {
|
|
28
|
+
const res = await baseFixture.fetch('/');
|
|
29
|
+
const html = await res.text();
|
|
30
|
+
const { document } = parseHTML(html);
|
|
31
|
+
expect(document.querySelector('#public > img')?.src).to.equal('/favicon.svg');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('transforms relative image paths to optimized path', async () => {
|
|
35
|
+
const res = await baseFixture.fetch('/');
|
|
36
|
+
const html = await res.text();
|
|
37
|
+
const { document } = parseHTML(html);
|
|
38
|
+
expect(document.querySelector('#relative > img')?.src).to.equal(
|
|
39
|
+
'/_image?href=%2Fsrc%2Fassets%2Frelative%2Foar.jpg%3ForigWidth%3D420%26origHeight%3D630%26origFormat%3Djpg&f=webp'
|
|
40
|
+
);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('transforms aliased image paths to optimized path', async () => {
|
|
44
|
+
const res = await baseFixture.fetch('/');
|
|
45
|
+
const html = await res.text();
|
|
46
|
+
const { document } = parseHTML(html);
|
|
47
|
+
expect(document.querySelector('#alias > img')?.src).to.equal(
|
|
48
|
+
'/_image?href=%2Fsrc%2Fassets%2Falias%2Fcityscape.jpg%3ForigWidth%3D420%26origHeight%3D280%26origFormat%3Djpg&f=webp'
|
|
49
|
+
);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe('build', () => {
|
|
54
|
+
before(async () => {
|
|
55
|
+
await baseFixture.build();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('uses public/ image paths unchanged', async () => {
|
|
59
|
+
const html = await baseFixture.readFile('/index.html');
|
|
60
|
+
const { document } = parseHTML(html);
|
|
61
|
+
expect(document.querySelector('#public > img')?.src).to.equal('/favicon.svg');
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('transforms relative image paths to optimized path', async () => {
|
|
65
|
+
const html = await baseFixture.readFile('/index.html');
|
|
66
|
+
const { document } = parseHTML(html);
|
|
67
|
+
expect(document.querySelector('#relative > img')?.src).to.match(/^\/_astro\/oar.*\.webp$/);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('transforms aliased image paths to optimized path', async () => {
|
|
71
|
+
const html = await baseFixture.readFile('/index.html');
|
|
72
|
+
const { document } = parseHTML(html);
|
|
73
|
+
expect(document.querySelector('#alias > img')?.src).to.match(/^\/_astro\/cityscape.*\.webp$/);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
});
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { parseHTML } from 'linkedom';
|
|
2
|
+
import { expect } from 'chai';
|
|
3
|
+
import { loadFixture } from '../../../astro/test/test-utils.js';
|
|
4
|
+
|
|
5
|
+
async function getFixture(name) {
|
|
6
|
+
return await loadFixture({
|
|
7
|
+
root: new URL(`./fixtures/${name}/`, import.meta.url),
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
describe('Markdoc - render', () => {
|
|
12
|
+
describe('dev', () => {
|
|
13
|
+
it('renders content - simple', async () => {
|
|
14
|
+
const fixture = await getFixture('render-simple');
|
|
15
|
+
const server = await fixture.startDevServer();
|
|
16
|
+
|
|
17
|
+
const res = await fixture.fetch('/');
|
|
18
|
+
const html = await res.text();
|
|
19
|
+
const { document } = parseHTML(html);
|
|
20
|
+
const h2 = document.querySelector('h2');
|
|
21
|
+
expect(h2.textContent).to.equal('Simple post');
|
|
22
|
+
const p = document.querySelector('p');
|
|
23
|
+
expect(p.textContent).to.equal('This is a simple Markdoc post.');
|
|
24
|
+
|
|
25
|
+
await server.stop();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('renders content - with config', async () => {
|
|
29
|
+
const fixture = await getFixture('render-with-config');
|
|
30
|
+
const server = await fixture.startDevServer();
|
|
31
|
+
|
|
32
|
+
const res = await fixture.fetch('/');
|
|
33
|
+
const html = await res.text();
|
|
34
|
+
const { document } = parseHTML(html);
|
|
35
|
+
const h2 = document.querySelector('h2');
|
|
36
|
+
expect(h2.textContent).to.equal('Post with config');
|
|
37
|
+
const textContent = html;
|
|
38
|
+
|
|
39
|
+
expect(textContent).to.not.include('Hello');
|
|
40
|
+
expect(textContent).to.include('Hola');
|
|
41
|
+
expect(textContent).to.include(`Konnichiwa`);
|
|
42
|
+
|
|
43
|
+
const runtimeVariable = document.querySelector('#runtime-variable');
|
|
44
|
+
expect(runtimeVariable?.textContent?.trim()).to.equal('working!');
|
|
45
|
+
|
|
46
|
+
await server.stop();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('renders content - with components', async () => {
|
|
50
|
+
const fixture = await getFixture('render-with-components');
|
|
51
|
+
const server = await fixture.startDevServer();
|
|
52
|
+
|
|
53
|
+
const res = await fixture.fetch('/');
|
|
54
|
+
const html = await res.text();
|
|
55
|
+
const { document } = parseHTML(html);
|
|
56
|
+
const h2 = document.querySelector('h2');
|
|
57
|
+
expect(h2.textContent).to.equal('Post with components');
|
|
58
|
+
|
|
59
|
+
// Renders custom shortcode component
|
|
60
|
+
const marquee = document.querySelector('marquee');
|
|
61
|
+
expect(marquee).to.not.be.null;
|
|
62
|
+
expect(marquee.hasAttribute('data-custom-marquee')).to.equal(true);
|
|
63
|
+
|
|
64
|
+
// Renders Astro Code component
|
|
65
|
+
const pre = document.querySelector('pre');
|
|
66
|
+
expect(pre).to.not.be.null;
|
|
67
|
+
expect(pre.className).to.equal('astro-code');
|
|
68
|
+
|
|
69
|
+
await server.stop();
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
describe('build', () => {
|
|
74
|
+
it('renders content - simple', async () => {
|
|
75
|
+
const fixture = await getFixture('render-simple');
|
|
76
|
+
await fixture.build();
|
|
77
|
+
|
|
78
|
+
const html = await fixture.readFile('/index.html');
|
|
79
|
+
const { document } = parseHTML(html);
|
|
80
|
+
const h2 = document.querySelector('h2');
|
|
81
|
+
expect(h2.textContent).to.equal('Simple post');
|
|
82
|
+
const p = document.querySelector('p');
|
|
83
|
+
expect(p.textContent).to.equal('This is a simple Markdoc post.');
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('renders content - with config', async () => {
|
|
87
|
+
const fixture = await getFixture('render-with-config');
|
|
88
|
+
await fixture.build();
|
|
89
|
+
|
|
90
|
+
const html = await fixture.readFile('/index.html');
|
|
91
|
+
const { document } = parseHTML(html);
|
|
92
|
+
const h2 = document.querySelector('h2');
|
|
93
|
+
expect(h2.textContent).to.equal('Post with config');
|
|
94
|
+
const textContent = html;
|
|
95
|
+
|
|
96
|
+
expect(textContent).to.not.include('Hello');
|
|
97
|
+
expect(textContent).to.include('Hola');
|
|
98
|
+
expect(textContent).to.include(`Konnichiwa`);
|
|
99
|
+
|
|
100
|
+
const runtimeVariable = document.querySelector('#runtime-variable');
|
|
101
|
+
expect(runtimeVariable?.textContent?.trim()).to.equal('working!');
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('renders content - with components', async () => {
|
|
105
|
+
const fixture = await getFixture('render-with-components');
|
|
106
|
+
await fixture.build();
|
|
107
|
+
|
|
108
|
+
const html = await fixture.readFile('/index.html');
|
|
109
|
+
const { document } = parseHTML(html);
|
|
110
|
+
const h2 = document.querySelector('h2');
|
|
111
|
+
expect(h2.textContent).to.equal('Post with components');
|
|
112
|
+
|
|
113
|
+
// Renders custom shortcode component
|
|
114
|
+
const marquee = document.querySelector('marquee');
|
|
115
|
+
expect(marquee).to.not.be.null;
|
|
116
|
+
expect(marquee.hasAttribute('data-custom-marquee')).to.equal(true);
|
|
117
|
+
|
|
118
|
+
// Renders Astro Code component
|
|
119
|
+
const pre = document.querySelector('pre');
|
|
120
|
+
expect(pre).to.not.be.null;
|
|
121
|
+
expect(pre.className).to.equal('astro-code');
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
});
|
|
File without changes
|
/package/test/fixtures/{content-collections → render-with-components}/src/components/Code.astro
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|