diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index 2134c2237706..75a251350374 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -124,7 +124,7 @@ export type TransitionAnimationValue = | TransitionDirectionalAnimations; // Allow users to extend this for astro-jsx.d.ts - + // eslint-disable-next-line @typescript-eslint/no-empty-object-type export interface AstroClientDirectives {} diff --git a/packages/astro/src/content/runtime.ts b/packages/astro/src/content/runtime.ts index e1128bc85311..b462e2e23a46 100644 --- a/packages/astro/src/content/runtime.ts +++ b/packages/astro/src/content/runtime.ts @@ -449,7 +449,12 @@ export async function renderEntry( // @ts-expect-error virtual module const { default: contentModules } = await import('astro:content-module-imports'); const module = contentModules.get(entry.filePath); - return await module(); + const deferredMod = await module(); + return { + Content: deferredMod.Content, + headings: deferredMod.getHeadings?.() ?? [], + remarkPluginFrontmatter: deferredMod.frontmatter ?? {}, + }; } catch (e) { // eslint-disable-next-line console.error(e); @@ -462,7 +467,11 @@ export async function renderEntry( : entry?.rendered?.html; const Content = createComponent(() => serverRender`${unescapeHTML(html)}`); - return { Content }; + return { + Content, + headings: entry?.rendered?.metadata?.headings ?? [], + remarkPluginFrontmatter: entry?.rendered?.metadata?.frontmatter ?? {}, + }; } async function render({ diff --git a/packages/astro/templates/content/types.d.ts b/packages/astro/templates/content/types.d.ts index 9880d724406c..9f277576a4bf 100644 --- a/packages/astro/templates/content/types.d.ts +++ b/packages/astro/templates/content/types.d.ts @@ -1,14 +1,14 @@ declare module 'astro:content' { - interface Render { - '.md': Promise<{ - Content: import('astro').MarkdownInstance<{}>['Content']; - headings: import('astro').MarkdownHeading[]; - remarkPluginFrontmatter: Record; - }>; - } - interface ContentLayerRenderResult { + + interface RenderResult { Content: import('astro/runtime/server/index.js').AstroComponentFactory; + headings: import('astro').MarkdownHeading[]; + remarkPluginFrontmatter: Record; } + interface Render { + '.md': Promise; + } + export interface RenderedContent { html: string; @@ -113,7 +113,7 @@ declare module 'astro:content' { export function render( entry: AnyEntryMap[C][string], - ): Promise; + ): Promise; export function reference( collection: C, diff --git a/packages/astro/test/fixtures/content-layer-rendering/content-outside-src-mdx/iguana.mdx b/packages/astro/test/fixtures/content-layer-rendering/content-outside-src-mdx/iguana.mdx index b34e732f5bb6..1266a73753b9 100644 --- a/packages/astro/test/fixtures/content-layer-rendering/content-outside-src-mdx/iguana.mdx +++ b/packages/astro/test/fixtures/content-layer-rendering/content-outside-src-mdx/iguana.mdx @@ -9,6 +9,8 @@ import H2 from "../src/components/H2.astro";

Iguana

+### Iguana + This is a rendered entry ![file](./shuttle.jpg) diff --git a/packages/astro/test/fixtures/content-layer/src/pages/spacecraft/[slug].astro b/packages/astro/test/fixtures/content-layer/src/pages/spacecraft/[slug].astro index b380a03c37ea..80314606f96f 100644 --- a/packages/astro/test/fixtures/content-layer/src/pages/spacecraft/[slug].astro +++ b/packages/astro/test/fixtures/content-layer/src/pages/spacecraft/[slug].astro @@ -22,12 +22,14 @@ export const getStaticPaths = (async () => { const { craft } = Astro.props as any let cat = craft.data.cat ? await getEntry(craft.data.cat) : undefined -const { Content } = await render(craft) +const { Content, headings } = await render(craft) ---

{craft.data.title}

+ {cat?

🐈: {cat.data.breed}

: undefined} {craft.data.heroImage ? {craft.data.title} : undefined} -