22import { Markdoc } from ' @astrojs/markdoc' ;
33import { Code } from ' astro/components' ;
44import Marquee from ' ../components/Marquee.astro' ;
5- import { getEntryBySlug } from ' astro:content' ;
5+ import { getCollection } from ' astro:content' ;
66import 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