Skip to content

Commit

Permalink
play: make sure md also works
Browse files Browse the repository at this point in the history
  • Loading branch information
bholmesdev committed Feb 16, 2023
1 parent dfdb35f commit e4f141e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 25 deletions.
8 changes: 8 additions & 0 deletions examples/with-markdoc/src/content/blog/plain-md.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: Markdown
---

## Just markdown

- working?
- yes.
4 changes: 2 additions & 2 deletions examples/with-markdoc/src/content/blog/test.mdoc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
title: Example!
title: Markdoc
---

# Hey there
# Markdoc h2

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

Expand Down
61 changes: 38 additions & 23 deletions examples/with-markdoc/src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@
import { Markdoc } from '@astrojs/markdoc';
import { Code } from 'astro/components';
import Marquee from '../components/Marquee.astro';
import { getEntryBySlug } from 'astro:content';
import { getCollection } from 'astro:content';
import RedP from '../components/RedP.astro';
const mdocEntry = await getEntryBySlug('blog', 'test');
const mdxEntry = await getEntryBySlug('blog', 'with-mdx');
console.log(mdocEntry);
const { Content } = await mdocEntry.render();
const { Content: MDXContent } = await mdxEntry.render();
const entries = await getCollection('blog');
---

<html lang="en">
Expand All @@ -23,23 +19,42 @@ const { Content: MDXContent } = await mdxEntry.render();
<body>
<h1>Astro</h1>
<article>
<MDXContent />
<Content
components={{
marquee: Marquee,
p: RedP,
pre: {
component: Code,
props({ attributes, getTreeNode }) {
return {
...attributes,
lang: attributes.lang ?? attributes['data-language'],
code: attributes.code ?? Markdoc.renderers.html(getTreeNode().children),
};
},
},
}}
/>
{
entries.map(async (entry) => {
const { Content } = await entry.render();
if (entry.id.endsWith('mdoc')) {
return (
<Fragment>
<h1>{entry.data.title}</h1>
<Content
components={{
marquee: Marquee,
p: RedP,
pre: {
component: Code,
props({ attributes, getTreeNode }) {
return {
...attributes,
lang: attributes.lang ?? attributes['data-language'],
code: attributes.code ?? Markdoc.renderers.html(getTreeNode().children),
};
},
},
}}
/>
<hr />
</Fragment>
);
}
return (
<>
<h1>{entry.data.title}</h1>
<Content />
<hr />
</>
);
})
}
</article>
</body>
</html>

0 comments on commit e4f141e

Please sign in to comment.