Skip to content

Commit b04c6da

Browse files
committed
feat(core): add markdownEnv to Page
1 parent b4e313b commit b04c6da

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

packages/core/src/page/createPage.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export const createPage = async (
3737
frontmatter,
3838
headers,
3939
links,
40+
markdownEnv,
4041
sfcBlocks,
4142
title,
4243
} = await renderPageContent({
@@ -123,6 +124,7 @@ export const createPage = async (
123124
date,
124125
deps,
125126
links,
127+
markdownEnv,
126128
pathInferred,
127129
pathLocale,
128130
permalink,

packages/core/src/page/renderPageContent.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export const renderPageContent = async ({
2424
}): Promise<{
2525
contentRendered: string
2626
deps: string[]
27+
markdownEnv: Record<string, unknown>
2728
frontmatter: PageFrontmatter
2829
headers: MarkdownHeader[]
2930
links: MarkdownLink[]
@@ -54,6 +55,19 @@ export const renderPageContent = async ({
5455
customBlocks: [],
5556
},
5657
title = '',
58+
59+
// values dropped from env
60+
61+
// eslint-disable-next-line @typescript-eslint/naming-convention
62+
base: _base,
63+
// eslint-disable-next-line @typescript-eslint/naming-convention
64+
content: _content,
65+
// eslint-disable-next-line @typescript-eslint/naming-convention
66+
filePath: _filePath,
67+
// eslint-disable-next-line @typescript-eslint/naming-convention
68+
filePathRelative: _filePathRelative,
69+
70+
...otherEnv
5771
} = markdownEnv
5872

5973
return {
@@ -62,6 +76,7 @@ export const renderPageContent = async ({
6276
frontmatter,
6377
headers,
6478
links,
79+
markdownEnv: otherEnv,
6580
sfcBlocks,
6681
title: frontmatter.title ?? title,
6782
}

packages/core/src/types/page.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ export type Page<
7474
*/
7575
routeMeta: Record<string, unknown>
7676

77+
/**
78+
* Markdown Environment of the page
79+
*/
80+
markdownEnv: Record<string, unknown>
81+
7782
/**
7883
* Extracted sfc blocks of the page
7984
*/

packages/core/tests/page/renderPageContent.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const msg = 'msg'
3131
frontmatter: {},
3232
headers: [],
3333
links: [],
34+
markdownEnv: { excerpt: '' },
3435
sfcBlocks: {
3536
template: {
3637
type: 'template',

0 commit comments

Comments
 (0)