Skip to content

Commit

Permalink
expose frontmatter (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
dtinth authored Apr 25, 2023
1 parent c4dd391 commit f245bdf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/grumpy-laws-poke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'contentsgarten': minor
---

expose frontMatter
9 changes: 8 additions & 1 deletion packages/contentsgarten/src/getPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const GetPageResult = z.object({
})
.optional(),
content: z.string(),
frontMatter: z.record(z.any()),
})
export type GetPageResult = z.infer<typeof GetPageResult>

Expand Down Expand Up @@ -50,10 +51,11 @@ export async function getPage(
},
})

const { content, status } = await (async () => {
const { content, frontMatter, status } = await (async () => {
if (!pageFile.data) {
return {
content: '(This page currently does not exist.)',
frontMatter: {},
status: 404,
} as const
}
Expand All @@ -65,6 +67,7 @@ export async function getPage(
}
return {
content: String(await engine.renderFile(pageRef, liquidCtx)),
frontMatter: pageData,
status: 200,
} as const
} catch (e: any) {
Expand All @@ -76,6 +79,7 @@ export async function getPage(
String(e?.stack || e),
'```',
].join('\n'),
frontMatter: {},
status: 500,
} as const
}
Expand All @@ -89,6 +93,7 @@ export async function getPage(
content: pageFile.data?.contents || '',
},
content,
frontMatter,
status,
}
return result
Expand Down Expand Up @@ -209,6 +214,7 @@ export async function getSpecialPage(
title: pageRef,
status: 200,
content: '',
frontMatter: {},
...(await specialPages[pageKey as keyof typeof specialPages]()),
}
}
Expand All @@ -217,6 +223,7 @@ export async function getSpecialPage(
title: pageRef,
content: '(There is no special page with this name.)',
status: 404,
frontMatter: {},
}
return result
}
Expand Down

1 comment on commit f245bdf

@hop-deploy
Copy link

@hop-deploy hop-deploy bot commented on f245bdf Apr 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deployment Status Build Logs Updated At
wonderwiki ✅ Deployed View Logs 2023-04-25T11:55:21.740Z

Please sign in to comment.