-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eaf4994
commit dfdb35f
Showing
14 changed files
with
265 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
packages/integrations/markdoc/test/content-collections.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { parseHTML } from 'linkedom'; | ||
import { parse as parseDevalue } from 'devalue'; | ||
import { expect } from 'chai'; | ||
import { loadFixture } from '../../../astro/test/test-utils.js'; | ||
|
||
describe('Markdoc - Content Collections', () => { | ||
let fixture; | ||
|
||
before(async () => { | ||
fixture = await loadFixture({ | ||
root: new URL('./fixtures/content-collections/', import.meta.url), | ||
}); | ||
}); | ||
|
||
describe('dev', () => { | ||
let devServer; | ||
|
||
before(async () => { | ||
devServer = await fixture.startDevServer(); | ||
}); | ||
|
||
after(async () => { | ||
await devServer.stop(); | ||
}); | ||
|
||
it('loads entry', async () => { | ||
const res = await fixture.fetch('/entry.json'); | ||
const post = parseDevalue(await res.text()); | ||
expect(post).to.deep.equal(simplePostEntry); | ||
}); | ||
|
||
it('loads collection', async () => { | ||
const res = await fixture.fetch('/collection.json'); | ||
const posts = parseDevalue(await res.text()); | ||
expect(posts).to.not.be.null; | ||
expect(posts.sort()).to.deep.equal([ | ||
simplePostEntry, | ||
{ | ||
id: 'with-components.mdoc', | ||
slug: 'with-components', | ||
collection: 'blog', | ||
data: { | ||
schemaWorks: true, | ||
title: 'Post with components', | ||
}, | ||
body: '\n## Post with components\n\nThis uses a custom marquee component with a shortcode:\n\n{% mq direction="right" %}\nI\'m a marquee too!\n{% /mq %}\n\nAnd a code component for code blocks:\n\n```js\nconst isRenderedWithShiki = true;\n```\n', | ||
}, | ||
{ | ||
id: 'with-config.mdoc', | ||
slug: 'with-config', | ||
collection: 'blog', | ||
data: { | ||
schemaWorks: true, | ||
title: 'Post with config', | ||
}, | ||
body: '\n## Post with config\n\nThis uses a shortcode to render a marquee element,\nwith a variable to show and hide:\n\n{% if $showMarquee %}\n{% mq direction="down" %}\nIm a marquee!\n{% /mq %}\n{% /if %}\n', | ||
}, | ||
]); | ||
}); | ||
}); | ||
}); | ||
|
||
const simplePostEntry = { | ||
id: 'simple.mdoc', | ||
slug: 'simple', | ||
collection: 'blog', | ||
data: { | ||
schemaWorks: true, | ||
title: 'Simple post', | ||
}, | ||
body: '\n## Simple post\n\nThis is a simple Markdoc post.\n', | ||
}; |
7 changes: 7 additions & 0 deletions
7
packages/integrations/markdoc/test/fixtures/content-collections/astro.config.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { defineConfig } from 'astro/config'; | ||
import markdoc from '@astrojs/markdoc'; | ||
|
||
// https://astro.build/config | ||
export default defineConfig({ | ||
integrations: [markdoc()], | ||
}); |
1 change: 1 addition & 0 deletions
1
...integrations/markdoc/test/fixtures/content-collections/src/components/CustomMarquee.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<marquee data-custom-marquee {...Astro.props}><slot /></marquee> |
7 changes: 7 additions & 0 deletions
7
packages/integrations/markdoc/test/fixtures/content-collections/src/content/blog/simple.mdoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
title: Simple post | ||
--- | ||
|
||
## Simple post | ||
|
||
This is a simple Markdoc post. |
17 changes: 17 additions & 0 deletions
17
...egrations/markdoc/test/fixtures/content-collections/src/content/blog/with-components.mdoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
title: Post with components | ||
--- | ||
|
||
## Post with components | ||
|
||
This uses a custom marquee component with a shortcode: | ||
|
||
{% mq direction="right" %} | ||
I'm a marquee too! | ||
{% /mq %} | ||
|
||
And a code component for code blocks: | ||
|
||
```js | ||
const isRenderedWithShiki = true; | ||
``` |
14 changes: 14 additions & 0 deletions
14
.../integrations/markdoc/test/fixtures/content-collections/src/content/blog/with-config.mdoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
title: Post with config | ||
--- | ||
|
||
## Post with config | ||
|
||
This uses a shortcode to render a marquee element, | ||
with a variable to show and hide: | ||
|
||
{% if $showMarquee %} | ||
{% mq direction="down" %} | ||
Im a marquee! | ||
{% /mq %} | ||
{% /if %} |
12 changes: 12 additions & 0 deletions
12
packages/integrations/markdoc/test/fixtures/content-collections/src/content/config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { defineCollection, z } from 'astro:content'; | ||
|
||
const blog = defineCollection({ | ||
schema: z.object({ | ||
title: z.string(), | ||
}).transform(data => ({ | ||
...data, | ||
schemaWorks: true, | ||
})) | ||
}); | ||
|
||
export const collections = { blog }; |
10 changes: 10 additions & 0 deletions
10
packages/integrations/markdoc/test/fixtures/content-collections/src/pages/collection.json.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { getCollection } from 'astro:content'; | ||
import { stringify } from 'devalue'; | ||
import { stripAllRenderFn } from '../../utils.js'; | ||
|
||
export async function get() { | ||
const posts = await getCollection('blog'); | ||
return { | ||
body: stringify(stripAllRenderFn(posts)) | ||
}; | ||
} |
18 changes: 18 additions & 0 deletions
18
...ges/integrations/markdoc/test/fixtures/content-collections/src/pages/content-simple.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
import { getEntryBySlug } from "astro:content"; | ||
const post = await getEntryBySlug('blog', 'simple'); | ||
const { Content } = await post.render(); | ||
--- | ||
|
||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Content - Simple</title> | ||
</head> | ||
<body> | ||
<Content /> | ||
</body> | ||
</html> |
50 changes: 50 additions & 0 deletions
50
...rations/markdoc/test/fixtures/content-collections/src/pages/content-with-components.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
--- | ||
import { getEntryBySlug } from "astro:content"; | ||
import { Code } from 'astro/components'; | ||
import CustomMarquee from '../components/CustomMarquee.astro'; | ||
import Markdoc from '@markdoc/markdoc'; | ||
const post = await getEntryBySlug('blog', 'with-components'); | ||
const { Content } = await post.render(); | ||
--- | ||
|
||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Content - with components</title> | ||
</head> | ||
<body> | ||
<Content | ||
config={{ | ||
tags: { | ||
mq: { | ||
render: 'marquee', | ||
attributes: { | ||
direction: { | ||
type: String, | ||
default: 'left', | ||
matches: ['left', 'right', 'up', 'down'], | ||
errorLevel: 'critical', | ||
}, | ||
}, | ||
}, | ||
} | ||
}} | ||
components={{ | ||
marquee: CustomMarquee, | ||
pre: { | ||
component: Code, | ||
props({ attributes, getTreeNode }) { | ||
return { | ||
lang: attributes['data-language'], | ||
code: Markdoc.renderers.html(getTreeNode().children), | ||
}; | ||
}, | ||
}, | ||
}} | ||
/> | ||
</body> | ||
</html> |
38 changes: 38 additions & 0 deletions
38
...ntegrations/markdoc/test/fixtures/content-collections/src/pages/content-with-config.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
import { getEntryBySlug } from "astro:content"; | ||
const post = await getEntryBySlug('blog', 'with-config'); | ||
const { Content } = await post.render(); | ||
--- | ||
|
||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Content - with config</title> | ||
</head> | ||
<body> | ||
<Content | ||
config={{ | ||
variables: { | ||
showMarquee: true, | ||
}, | ||
tags: { | ||
mq: { | ||
render: 'marquee', | ||
attributes: { | ||
direction: { | ||
type: String, | ||
default: 'left', | ||
matches: ['left', 'right', 'up', 'down'], | ||
errorLevel: 'critical', | ||
}, | ||
}, | ||
}, | ||
} | ||
}} | ||
/> | ||
</body> | ||
</html> |
10 changes: 10 additions & 0 deletions
10
packages/integrations/markdoc/test/fixtures/content-collections/src/pages/entry.json.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { getEntryBySlug } from 'astro:content'; | ||
import { stringify } from 'devalue'; | ||
import { stripRenderFn } from '../../utils.js'; | ||
|
||
export async function get() { | ||
const post = await getEntryBySlug('blog', 'simple'); | ||
return { | ||
body: stringify(stripRenderFn(post)), | ||
}; | ||
} |
8 changes: 8 additions & 0 deletions
8
packages/integrations/markdoc/test/fixtures/content-collections/utils.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export function stripRenderFn(entryWithRender) { | ||
const { render, ...entry } = entryWithRender; | ||
return entry; | ||
} | ||
|
||
export function stripAllRenderFn(collection = []) { | ||
return collection.map(stripRenderFn); | ||
} |