summaryrefslogtreecommitdiff
path: root/packages/integrations/markdoc/components/Renderer.astro
blob: c26d92ad737ac3d428dcc3ce3527ba5abf9d45b6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
---
//! astro-head-inject
import type { Config } from '@markdoc/markdoc';
import Markdoc from '@markdoc/markdoc';
import { ComponentNode, createTreeNode } from './TreeNode.js';

type Props = {
	config: Config;
	stringifiedAst: string;
};

const { stringifiedAst, config } = Astro.props as Props;

const ast = Markdoc.Ast.fromJSON(stringifiedAst);
const content = await Markdoc.transform(ast, config);
---

{
	Array.isArray(content) ? (
		content.map(async (c) => <ComponentNode treeNode={await createTreeNode(c)} />)
	) : (
		<ComponentNode treeNode={await createTreeNode(content)} />
	)
}