Skip to content

Commit e4f141e

Browse files
committed
play: make sure md also works
1 parent dfdb35f commit e4f141e

File tree

3 files changed

+48
-25
lines changed

3 files changed

+48
-25
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
title: Markdown
3+
---
4+
5+
## Just markdown
6+
7+
- working?
8+
- yes.

examples/with-markdoc/src/content/blog/test.mdoc

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
2-
title: Example!
2+
title: Markdoc
33
---
44

5-
# Hey there
5+
# Markdoc h2
66

77
Look at this table! Built-in to Markdoc, neat.
88

examples/with-markdoc/src/pages/index.astro

+38-23
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,10 @@
22
import { Markdoc } from '@astrojs/markdoc';
33
import { Code } from 'astro/components';
44
import Marquee from '../components/Marquee.astro';
5-
import { getEntryBySlug } from 'astro:content';
5+
import { getCollection } from 'astro:content';
66
import RedP from '../components/RedP.astro';
77
8-
const mdocEntry = await getEntryBySlug('blog', 'test');
9-
const mdxEntry = await getEntryBySlug('blog', 'with-mdx');
10-
console.log(mdocEntry);
11-
const { Content } = await mdocEntry.render();
12-
const { Content: MDXContent } = await mdxEntry.render();
8+
const entries = await getCollection('blog');
139
---
1410

1511
<html lang="en">
@@ -23,23 +19,42 @@ const { Content: MDXContent } = await mdxEntry.render();
2319
<body>
2420
<h1>Astro</h1>
2521
<article>
26-
<MDXContent />
27-
<Content
28-
components={{
29-
marquee: Marquee,
30-
p: RedP,
31-
pre: {
32-
component: Code,
33-
props({ attributes, getTreeNode }) {
34-
return {
35-
...attributes,
36-
lang: attributes.lang ?? attributes['data-language'],
37-
code: attributes.code ?? Markdoc.renderers.html(getTreeNode().children),
38-
};
39-
},
40-
},
41-
}}
42-
/>
22+
{
23+
entries.map(async (entry) => {
24+
const { Content } = await entry.render();
25+
if (entry.id.endsWith('mdoc')) {
26+
return (
27+
<Fragment>
28+
<h1>{entry.data.title}</h1>
29+
<Content
30+
components={{
31+
marquee: Marquee,
32+
p: RedP,
33+
pre: {
34+
component: Code,
35+
props({ attributes, getTreeNode }) {
36+
return {
37+
...attributes,
38+
lang: attributes.lang ?? attributes['data-language'],
39+
code: attributes.code ?? Markdoc.renderers.html(getTreeNode().children),
40+
};
41+
},
42+
},
43+
}}
44+
/>
45+
<hr />
46+
</Fragment>
47+
);
48+
}
49+
return (
50+
<>
51+
<h1>{entry.data.title}</h1>
52+
<Content />
53+
<hr />
54+
</>
55+
);
56+
})
57+
}
4358
</article>
4459
</body>
4560
</html>

0 commit comments

Comments
 (0)