@astrojs/markdoc 0.0.0-data-collections-20230418125011
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 -0
- package/CHANGELOG.md +129 -0
- package/LICENSE +61 -0
- package/README.md +326 -0
- package/components/Renderer.astro +17 -0
- package/components/TreeNode.ts +81 -0
- package/components/index.ts +2 -0
- 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 +2 -0
- package/dist/index.js +114 -0
- package/dist/load-config.d.ts +14 -0
- package/dist/load-config.js +82 -0
- package/dist/utils.d.ts +40 -0
- package/dist/utils.js +60 -0
- package/package.json +62 -0
- 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 +164 -0
- package/src/load-config.ts +102 -0
- package/src/utils.ts +98 -0
- package/template/content-module-types.d.ts +7 -0
- package/test/content-collections.test.js +110 -0
- package/test/entry-prop.test.js +58 -0
- package/test/fixtures/content-collections/astro.config.mjs +7 -0
- package/test/fixtures/content-collections/node_modules/.bin/astro +17 -0
- package/test/fixtures/content-collections/package.json +9 -0
- 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/content/config.ts +12 -0
- package/test/fixtures/content-collections/src/pages/collection.json.js +10 -0
- package/test/fixtures/content-collections/src/pages/entry.json.js +10 -0
- package/test/fixtures/content-collections/utils.js +8 -0
- package/test/fixtures/entry-prop/astro.config.mjs +7 -0
- package/test/fixtures/entry-prop/node_modules/.bin/astro +17 -0
- package/test/fixtures/entry-prop/package.json +9 -0
- package/test/fixtures/entry-prop/src/content/blog/entry.mdoc +9 -0
- package/test/fixtures/entry-prop/src/content/config.ts +9 -0
- package/test/fixtures/entry-prop/src/pages/index.astro +19 -0
- 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-null/astro.config.mjs +7 -0
- package/test/fixtures/render-null/markdoc.config.mjs +26 -0
- package/test/fixtures/render-null/node_modules/.bin/astro +17 -0
- package/test/fixtures/render-null/package.json +9 -0
- package/test/fixtures/render-null/src/content/blog/render-null.mdoc +7 -0
- package/test/fixtures/render-null/src/pages/index.astro +19 -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/render-simple/src/content/blog/simple.mdoc +7 -0
- package/test/fixtures/render-simple/src/pages/index.astro +19 -0
- 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/render-with-components/src/components/Code.astro +12 -0
- package/test/fixtures/render-with-components/src/components/CustomMarquee.astro +1 -0
- package/test/fixtures/render-with-components/src/content/blog/with-components.mdoc +17 -0
- package/test/fixtures/render-with-components/src/pages/index.astro +19 -0
- 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/render-with-config/src/content/blog/with-config.mdoc +13 -0
- package/test/fixtures/render-with-config/src/pages/index.astro +19 -0
- package/test/image-assets.test.js +76 -0
- package/test/render.test.js +150 -0
- package/tsconfig.json +10 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { defineMarkdocConfig } from '@astrojs/markdoc/config';
|
|
2
|
+
|
|
3
|
+
export default defineMarkdocConfig({
|
|
4
|
+
nodes: {
|
|
5
|
+
document: {
|
|
6
|
+
render: null,
|
|
7
|
+
|
|
8
|
+
// Defaults from `Markdoc.nodes.document`
|
|
9
|
+
children: [
|
|
10
|
+
'heading',
|
|
11
|
+
'paragraph',
|
|
12
|
+
'image',
|
|
13
|
+
'table',
|
|
14
|
+
'tag',
|
|
15
|
+
'fence',
|
|
16
|
+
'blockquote',
|
|
17
|
+
'comment',
|
|
18
|
+
'list',
|
|
19
|
+
'hr',
|
|
20
|
+
],
|
|
21
|
+
attributes: {
|
|
22
|
+
frontmatter: { render: false },
|
|
23
|
+
},
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
})
|
|
@@ -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
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
---
|
|
2
|
+
import { getEntryBySlug } from "astro:content";
|
|
3
|
+
|
|
4
|
+
const post = await getEntryBySlug('blog', 'render-null');
|
|
5
|
+
const { Content } = await post.render();
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
<!DOCTYPE html>
|
|
9
|
+
<html lang="en">
|
|
10
|
+
<head>
|
|
11
|
+
<meta charset="UTF-8">
|
|
12
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
13
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
14
|
+
<title>Content</title>
|
|
15
|
+
</head>
|
|
16
|
+
<body>
|
|
17
|
+
<Content />
|
|
18
|
+
</body>
|
|
19
|
+
</html>
|
|
@@ -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
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
---
|
|
2
|
+
import { getEntryBySlug } from "astro:content";
|
|
3
|
+
|
|
4
|
+
const post = await getEntryBySlug('blog', 'simple');
|
|
5
|
+
const { Content } = await post.render();
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
<!DOCTYPE html>
|
|
9
|
+
<html lang="en">
|
|
10
|
+
<head>
|
|
11
|
+
<meta charset="UTF-8">
|
|
12
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
13
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
14
|
+
<title>Content</title>
|
|
15
|
+
</head>
|
|
16
|
+
<body>
|
|
17
|
+
<Content />
|
|
18
|
+
</body>
|
|
19
|
+
</html>
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import Code from './src/components/Code.astro';
|
|
2
|
+
import CustomMarquee from './src/components/CustomMarquee.astro';
|
|
3
|
+
import { defineMarkdocConfig } from '@astrojs/markdoc/config';
|
|
4
|
+
|
|
5
|
+
export default defineMarkdocConfig({
|
|
6
|
+
nodes: {
|
|
7
|
+
fence: {
|
|
8
|
+
render: Code,
|
|
9
|
+
attributes: {
|
|
10
|
+
language: { type: String },
|
|
11
|
+
content: { type: String },
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
tags: {
|
|
16
|
+
mq: {
|
|
17
|
+
render: CustomMarquee,
|
|
18
|
+
attributes: {
|
|
19
|
+
direction: {
|
|
20
|
+
type: String,
|
|
21
|
+
default: 'left',
|
|
22
|
+
matches: ['left', 'right', 'up', 'down'],
|
|
23
|
+
errorLevel: 'critical',
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
})
|
|
@@ -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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<marquee data-custom-marquee {...Astro.props}><slot /></marquee>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Post with components
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
## Post with components
|
|
6
|
+
|
|
7
|
+
This uses a custom marquee component with a shortcode:
|
|
8
|
+
|
|
9
|
+
{% mq direction="right" %}
|
|
10
|
+
I'm a marquee too!
|
|
11
|
+
{% /mq %}
|
|
12
|
+
|
|
13
|
+
And a code component for code blocks:
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
const isRenderedWithShiki = true;
|
|
17
|
+
```
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
---
|
|
2
|
+
import { getEntryBySlug } from "astro:content";
|
|
3
|
+
|
|
4
|
+
const post = await getEntryBySlug('blog', 'with-components');
|
|
5
|
+
const { Content } = await post.render();
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
<!DOCTYPE html>
|
|
9
|
+
<html lang="en">
|
|
10
|
+
<head>
|
|
11
|
+
<meta charset="UTF-8">
|
|
12
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
13
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
14
|
+
<title>Content</title>
|
|
15
|
+
</head>
|
|
16
|
+
<body>
|
|
17
|
+
<Content />
|
|
18
|
+
</body>
|
|
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/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
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Post with config
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
## Post with config
|
|
6
|
+
|
|
7
|
+
{% if includes($countries, "EN") %} Hello {% /if %}
|
|
8
|
+
{% if includes($countries, "ES") %} Hola {% /if %}
|
|
9
|
+
{% if includes($countries, "JP") %} Konnichiwa {% /if %}
|
|
10
|
+
|
|
11
|
+
## Runtime variables
|
|
12
|
+
|
|
13
|
+
{% $runtimeVariable %} {% #runtime-variable %}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
---
|
|
2
|
+
import { getEntryBySlug } from "astro:content";
|
|
3
|
+
|
|
4
|
+
const post = await getEntryBySlug('blog', 'with-config');
|
|
5
|
+
const { Content } = await post.render();
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
<!DOCTYPE html>
|
|
9
|
+
<html lang="en">
|
|
10
|
+
<head>
|
|
11
|
+
<meta charset="UTF-8">
|
|
12
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
13
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
14
|
+
<title>Content</title>
|
|
15
|
+
</head>
|
|
16
|
+
<body>
|
|
17
|
+
<Content runtimeVariable="working!" />
|
|
18
|
+
</body>
|
|
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,150 @@
|
|
|
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
|
+
|
|
20
|
+
renderSimpleChecks(html);
|
|
21
|
+
|
|
22
|
+
await server.stop();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('renders content - with config', async () => {
|
|
26
|
+
const fixture = await getFixture('render-with-config');
|
|
27
|
+
const server = await fixture.startDevServer();
|
|
28
|
+
|
|
29
|
+
const res = await fixture.fetch('/');
|
|
30
|
+
const html = await res.text();
|
|
31
|
+
|
|
32
|
+
renderConfigChecks(html);
|
|
33
|
+
|
|
34
|
+
await server.stop();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('renders content - with components', async () => {
|
|
38
|
+
const fixture = await getFixture('render-with-components');
|
|
39
|
+
const server = await fixture.startDevServer();
|
|
40
|
+
|
|
41
|
+
const res = await fixture.fetch('/');
|
|
42
|
+
const html = await res.text();
|
|
43
|
+
|
|
44
|
+
renderComponentsChecks(html);
|
|
45
|
+
|
|
46
|
+
await server.stop();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('renders content - with `render: null` in document', async () => {
|
|
50
|
+
const fixture = await getFixture('render-null');
|
|
51
|
+
const server = await fixture.startDevServer();
|
|
52
|
+
|
|
53
|
+
const res = await fixture.fetch('/');
|
|
54
|
+
const html = await res.text();
|
|
55
|
+
|
|
56
|
+
renderNullChecks(html);
|
|
57
|
+
|
|
58
|
+
await server.stop();
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
describe('build', () => {
|
|
63
|
+
it('renders content - simple', async () => {
|
|
64
|
+
const fixture = await getFixture('render-simple');
|
|
65
|
+
await fixture.build();
|
|
66
|
+
|
|
67
|
+
const html = await fixture.readFile('/index.html');
|
|
68
|
+
|
|
69
|
+
renderSimpleChecks(html);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('renders content - with config', async () => {
|
|
73
|
+
const fixture = await getFixture('render-with-config');
|
|
74
|
+
await fixture.build();
|
|
75
|
+
|
|
76
|
+
const html = await fixture.readFile('/index.html');
|
|
77
|
+
|
|
78
|
+
renderConfigChecks(html);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('renders content - with components', async () => {
|
|
82
|
+
const fixture = await getFixture('render-with-components');
|
|
83
|
+
await fixture.build();
|
|
84
|
+
|
|
85
|
+
const html = await fixture.readFile('/index.html');
|
|
86
|
+
|
|
87
|
+
renderComponentsChecks(html);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('renders content - with `render: null` in document', async () => {
|
|
91
|
+
const fixture = await getFixture('render-null');
|
|
92
|
+
await fixture.build();
|
|
93
|
+
|
|
94
|
+
const html = await fixture.readFile('/index.html');
|
|
95
|
+
|
|
96
|
+
renderNullChecks(html);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* @param {string} html
|
|
103
|
+
*/
|
|
104
|
+
function renderNullChecks(html) {
|
|
105
|
+
const { document } = parseHTML(html);
|
|
106
|
+
const h2 = document.querySelector('h2');
|
|
107
|
+
expect(h2.textContent).to.equal('Post with render null');
|
|
108
|
+
expect(h2.parentElement?.tagName).to.equal('BODY');
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** @param {string} html */
|
|
112
|
+
function renderComponentsChecks(html) {
|
|
113
|
+
const { document } = parseHTML(html);
|
|
114
|
+
const h2 = document.querySelector('h2');
|
|
115
|
+
expect(h2.textContent).to.equal('Post with components');
|
|
116
|
+
|
|
117
|
+
// Renders custom shortcode component
|
|
118
|
+
const marquee = document.querySelector('marquee');
|
|
119
|
+
expect(marquee).to.not.be.null;
|
|
120
|
+
expect(marquee.hasAttribute('data-custom-marquee')).to.equal(true);
|
|
121
|
+
|
|
122
|
+
// Renders Astro Code component
|
|
123
|
+
const pre = document.querySelector('pre');
|
|
124
|
+
expect(pre).to.not.be.null;
|
|
125
|
+
expect(pre.className).to.equal('astro-code');
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** @param {string} html */
|
|
129
|
+
function renderConfigChecks(html) {
|
|
130
|
+
const { document } = parseHTML(html);
|
|
131
|
+
const h2 = document.querySelector('h2');
|
|
132
|
+
expect(h2.textContent).to.equal('Post with config');
|
|
133
|
+
const textContent = html;
|
|
134
|
+
|
|
135
|
+
expect(textContent).to.not.include('Hello');
|
|
136
|
+
expect(textContent).to.include('Hola');
|
|
137
|
+
expect(textContent).to.include(`Konnichiwa`);
|
|
138
|
+
|
|
139
|
+
const runtimeVariable = document.querySelector('#runtime-variable');
|
|
140
|
+
expect(runtimeVariable?.textContent?.trim()).to.equal('working!');
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** @param {string} html */
|
|
144
|
+
function renderSimpleChecks(html) {
|
|
145
|
+
const { document } = parseHTML(html);
|
|
146
|
+
const h2 = document.querySelector('h2');
|
|
147
|
+
expect(h2.textContent).to.equal('Simple post');
|
|
148
|
+
const p = document.querySelector('p');
|
|
149
|
+
expect(p.textContent).to.equal('This is a simple Markdoc post.');
|
|
150
|
+
}
|