diff --git a/apps/web/src/app/page.tsx b/apps/web/src/app/page.tsx
index 1a4632c..7dd6ac8 100644
--- a/apps/web/src/app/page.tsx
+++ b/apps/web/src/app/page.tsx
@@ -11,9 +11,9 @@ export default async function Page() {
{posts.map((post) => (
- -
+
-
- {post.title} {post.author && <>by {post.author}>}
+ {post.data.title} {post.data.author && <>by {post.data.author}>}
))}
diff --git a/packages/typed-mdx/src/index.ts b/packages/typed-mdx/src/index.ts
index 000793f..78fc053 100644
--- a/packages/typed-mdx/src/index.ts
+++ b/packages/typed-mdx/src/index.ts
@@ -80,14 +80,8 @@ async function stringifyMDX(mdxPath: string): Promise {
}
const metadataSchema = z.object({
- metadata: z.object({
- slug: z.string(),
- filePath: z.string(),
- }),
-});
-
-const bodySchema = z.object({
- body: z.string(),
+ slug: z.string(),
+ filePath: z.string(),
});
const MDX_ENTENSION = ".mdx";
@@ -99,7 +93,11 @@ async function getAll({
folder: string;
schema: Z;
}): Promise<
- (z.infer & z.infer & z.infer)[]
+ {
+ data: z.infer;
+ body: string;
+ metadata: z.infer;
+ }[]
> {
assertSchemaIsObject(schema);
@@ -116,7 +114,7 @@ async function getAll({
const mdxFileNames = postFilePaths.filter(
(postFilePath) => path.extname(postFilePath).toLowerCase() === MDX_ENTENSION
);
- const data = await Promise.all(
+ return await Promise.all(
mdxFileNames.map(async (mdxFileName) => {
const parsedFrontmatter = await parseMdxFile(
`${folderPath}/${mdxFileName}`,
@@ -133,12 +131,9 @@ async function getAll({
};
const body = await stringifyMDX(`${folderPath}/${mdxFileName}`);
- return { metadata, body, ...parsedFrontmatter };
+ return { metadata, body, data: parsedFrontmatter };
})
);
- return z
- .array(schema.merge(metadataSchema).merge(bodySchema))
- .parse(data.filter(Boolean)) as any; // TODO FIX THIS ANY
}
async function getBySlug({
@@ -149,9 +144,11 @@ async function getBySlug({
folder: string;
schema: Z;
slug: string;
-}): Promise<
- z.infer & z.infer & z.infer
-> {
+}): Promise<{
+ data: z.infer;
+ body: string;
+ metadata: z.infer;
+}> {
assertSchemaIsObject(schema);
const filePath = `${CONTENT_FOLDER}/${folder}/${slug}.mdx` as const;
@@ -178,16 +175,18 @@ export function defineCollection(options: {
strict?: boolean;
}): {
getAll: () => Promise<
- Prettify<
- z.infer & z.infer & z.infer
- >[]
+ Prettify<{
+ data: z.infer;
+ body: string;
+ metadata: z.infer;
+ }>[]
>;
- getBySlug: (
- slug: string
- ) => Promise<
- Prettify<
- z.infer & z.infer & z.infer
- >
+ getBySlug: (slug: string) => Promise<
+ Prettify<{
+ data: z.infer;
+ body: string;
+ metadata: z.infer;
+ }>
>;
schema: Z;
} {