From 9746a97bc2dfcf63bfd685f541ffbd229ea134ca Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Thu, 9 Feb 2023 12:16:02 -0500 Subject: [PATCH] refactor: pass file contents --- packages/astro/src/@types/astro.ts | 2 +- packages/astro/src/content/vite-plugin-content-imports.ts | 5 ++++- packages/integrations/markdoc/src/index.ts | 6 ++---- packages/integrations/mdx/src/index.ts | 5 ++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index 390f3c715219..1975f9db179d 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -979,7 +979,7 @@ export interface AstroConfig extends z.output { export interface ContentEntryType { extensions: string[]; - getEntryInfo(params: { fileUrl: URL }): Promise<{ + getEntryInfo(params: { fileUrl: URL; contents: string }): Promise<{ data: Record; /** * Used for error hints to point to correct line and location diff --git a/packages/astro/src/content/vite-plugin-content-imports.ts b/packages/astro/src/content/vite-plugin-content-imports.ts index f36829c19398..b9f6644b9a3f 100644 --- a/packages/astro/src/content/vite-plugin-content-imports.ts +++ b/packages/astro/src/content/vite-plugin-content-imports.ts @@ -79,7 +79,10 @@ export function astroContentImportPlugin({ unvalidatedSlug: string, rawData: string; if (contentEntryType) { - const info = await contentEntryType.getEntryInfo({ fileUrl: pathToFileURL(fileId) }); + const info = await contentEntryType.getEntryInfo({ + fileUrl: pathToFileURL(fileId), + contents: rawContents, + }); body = info.body; unvalidatedData = info.data; unvalidatedSlug = info.slug; diff --git a/packages/integrations/markdoc/src/index.ts b/packages/integrations/markdoc/src/index.ts index 17c433ef31e3..4062892f9c9f 100644 --- a/packages/integrations/markdoc/src/index.ts +++ b/packages/integrations/markdoc/src/index.ts @@ -1,15 +1,13 @@ import type { AstroIntegration } from 'astro'; import type { InlineConfig } from 'vite'; import _Markdoc from '@markdoc/markdoc'; -import fs from 'node:fs'; import { parseFrontmatter } from './utils.js'; import { fileURLToPath } from 'node:url'; const contentEntryType = { extensions: ['.mdoc'], - async getEntryInfo({ fileUrl }: { fileUrl: URL }) { - const rawContents = await fs.promises.readFile(fileUrl, 'utf-8'); - const parsed = parseFrontmatter(rawContents, fileURLToPath(fileUrl)); + async getEntryInfo({ fileUrl, contents }: { fileUrl: URL; contents: string }) { + const parsed = parseFrontmatter(contents, fileURLToPath(fileUrl)); return { data: parsed.data, body: parsed.content, diff --git a/packages/integrations/mdx/src/index.ts b/packages/integrations/mdx/src/index.ts index 42e6459672a2..61f60ba0bbf6 100644 --- a/packages/integrations/mdx/src/index.ts +++ b/packages/integrations/mdx/src/index.ts @@ -25,9 +25,8 @@ export type MdxOptions = Omit