diff --git a/packages/integrations/markdoc/components/Renderer.astro b/packages/integrations/markdoc/components/Renderer.astro index 00c602c7d..2079a5168 100644 --- a/packages/integrations/markdoc/components/Renderer.astro +++ b/packages/integrations/markdoc/components/Renderer.astro @@ -1,11 +1,12 @@ --- import type { RenderableTreeNode } from '@markdoc/markdoc'; -import { ComponentRenderer, createAstroNode } from './astroNode'; +import type { AstroInstance } from 'astro'; +import { createAstroNode } from './astroNode'; import RenderNode from './RenderNode.astro'; type Props = { content: RenderableTreeNode; - components: Record; + components: Record; }; const { content, components } = Astro.props as Props; diff --git a/packages/integrations/markdoc/components/astroNode.ts b/packages/integrations/markdoc/components/astroNode.ts index 8f6420342..0e9ce0fb0 100644 --- a/packages/integrations/markdoc/components/astroNode.ts +++ b/packages/integrations/markdoc/components/astroNode.ts @@ -1,18 +1,11 @@ -import type { ComponentInstance } from 'astro'; -import type { RenderableTreeNode, Tag } from '@markdoc/markdoc'; +import type { AstroInstance } from 'astro'; +import type { RenderableTreeNode } from '@markdoc/markdoc'; import Markdoc from '@markdoc/markdoc'; -export type ComponentRenderer = - | ComponentInstance['default'] - | { - component: ComponentInstance['default']; - props?(params: { attributes: Record; getTreeNode(): Tag }): Record; - }; - export type AstroNode = | string | { - component: ComponentInstance['default']; + component: AstroInstance['default']; props: Record; children: AstroNode[]; } @@ -24,7 +17,7 @@ export type AstroNode = export function createAstroNode( node: RenderableTreeNode, - components: Record = {} + components: Record = {} ): AstroNode { if (typeof node === 'string' || typeof node === 'number') { return String(node); @@ -33,18 +26,10 @@ export function createAstroNode( } if (node.name in components) { - const componentRenderer = components[node.name]; - const component = - 'component' in componentRenderer ? componentRenderer.component : componentRenderer; - const props = - 'props' in componentRenderer && typeof componentRenderer.props === 'function' - ? componentRenderer.props({ - attributes: node.attributes, - getTreeNode() { - return node; - }, - }) - : node.attributes; + const component = components[node.name]; + const props = node.attributes; + + console.log({ node, component, props, components }); const children = node.children.map((child) => createAstroNode(child, components)); diff --git a/packages/integrations/markdoc/template/content-module-types.d.ts b/packages/integrations/markdoc/template/content-module-types.d.ts index a3a4b19c3..87c17af24 100644 --- a/packages/integrations/markdoc/template/content-module-types.d.ts +++ b/packages/integrations/markdoc/template/content-module-types.d.ts @@ -1,18 +1,8 @@ declare module 'astro:content' { - type ComponentRenderer = - | import('astro').ComponentInstance['default'] - | { - component: import('astro').ComponentInstance['default']; - props?(params: { - attributes: Record; - getTreeNode(): typeof import('@astrojs/markdoc').Markdoc.Tag; - }): Record; - }; - interface Render { '.mdoc': Promise<{ Content(props: { - components?: Record; + components?: Record; }): import('astro').MarkdownInstance<{}>['Content']; }>; }