2
2
import { Markdoc } from ' @astrojs/markdoc' ;
3
3
import { Code } from ' astro/components' ;
4
4
import Marquee from ' ../components/Marquee.astro' ;
5
- import { getEntryBySlug } from ' astro:content' ;
5
+ import { getCollection } from ' astro:content' ;
6
6
import RedP from ' ../components/RedP.astro' ;
7
7
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' );
13
9
---
14
10
15
11
<html lang =" en" >
@@ -23,23 +19,42 @@ const { Content: MDXContent } = await mdxEntry.render();
23
19
<body >
24
20
<h1 >Astro</h1 >
25
21
<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
+ }
43
58
</article >
44
59
</body >
45
60
</html >
0 commit comments