Skip to content

Commit

Permalink
feat(core): add markdownEnv to Page
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Hope committed Jan 7, 2023
1 parent b4e313b commit b04c6da
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/core/src/page/createPage.ts
Expand Up @@ -37,6 +37,7 @@ export const createPage = async (
frontmatter,
headers,
links,
markdownEnv,
sfcBlocks,
title,
} = await renderPageContent({
Expand Down Expand Up @@ -123,6 +124,7 @@ export const createPage = async (
date,
deps,
links,
markdownEnv,
pathInferred,
pathLocale,
permalink,
Expand Down
15 changes: 15 additions & 0 deletions packages/core/src/page/renderPageContent.ts
Expand Up @@ -24,6 +24,7 @@ export const renderPageContent = async ({
}): Promise<{
contentRendered: string
deps: string[]
markdownEnv: Record<string, unknown>
frontmatter: PageFrontmatter
headers: MarkdownHeader[]
links: MarkdownLink[]
Expand Down Expand Up @@ -54,6 +55,19 @@ export const renderPageContent = async ({
customBlocks: [],
},
title = '',

// values dropped from env

// eslint-disable-next-line @typescript-eslint/naming-convention
base: _base,
// eslint-disable-next-line @typescript-eslint/naming-convention
content: _content,
// eslint-disable-next-line @typescript-eslint/naming-convention
filePath: _filePath,
// eslint-disable-next-line @typescript-eslint/naming-convention
filePathRelative: _filePathRelative,

...otherEnv
} = markdownEnv

return {
Expand All @@ -62,6 +76,7 @@ export const renderPageContent = async ({
frontmatter,
headers,
links,
markdownEnv: otherEnv,
sfcBlocks,
title: frontmatter.title ?? title,
}
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/types/page.ts
Expand Up @@ -74,6 +74,11 @@ export type Page<
*/
routeMeta: Record<string, unknown>

/**
* Markdown Environment of the page
*/
markdownEnv: Record<string, unknown>

/**
* Extracted sfc blocks of the page
*/
Expand Down
1 change: 1 addition & 0 deletions packages/core/tests/page/renderPageContent.spec.ts
Expand Up @@ -31,6 +31,7 @@ const msg = 'msg'
frontmatter: {},
headers: [],
links: [],
markdownEnv: { excerpt: '' },
sfcBlocks: {
template: {
type: 'template',
Expand Down

0 comments on commit b04c6da

Please sign in to comment.