Skip to content

Commit

Permalink
refactor: pass file contents
Browse files Browse the repository at this point in the history
  • Loading branch information
bholmesdev committed Feb 16, 2023
1 parent 534a658 commit 9746a97
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/astro/src/@types/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ export interface AstroConfig extends z.output<typeof AstroConfigSchema> {

export interface ContentEntryType {
extensions: string[];
getEntryInfo(params: { fileUrl: URL }): Promise<{
getEntryInfo(params: { fileUrl: URL; contents: string }): Promise<{
data: Record<string, unknown>;
/**
* Used for error hints to point to correct line and location
Expand Down
5 changes: 4 additions & 1 deletion packages/astro/src/content/vite-plugin-content-imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 2 additions & 4 deletions packages/integrations/markdoc/src/index.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
5 changes: 2 additions & 3 deletions packages/integrations/mdx/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ export type MdxOptions = Omit<typeof markdownConfigDefaults, 'remarkPlugins' | '

const contentEntryType = {
extensions: ['.mdx'],
async getEntryInfo({ fileUrl }: { fileUrl: URL }) {
const rawContents = await fs.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,
Expand Down

0 comments on commit 9746a97

Please sign in to comment.