Skip to content

Commit f977192

Browse files
committed
feat(core): make frontmatter available in markdown env
1 parent 89a32b5 commit f977192

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

packages/@vuepress/core/src/page/createPage.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@ export const createPage = async (
3939
const frontmatter = resolvePageFrontmatter({ frontmatterRaw, options })
4040

4141
// resolve excerpt from raw excerpt
42-
const excerpt = resolvePageExcerpt({ excerptRaw, app, filePathRelative })
42+
const excerpt = resolvePageExcerpt({
43+
app,
44+
excerptRaw,
45+
filePathRelative,
46+
frontmatter,
47+
})
4348

4449
// resolve slug from file path
4550
const slug = resolvePageSlug({ filePathRelative })
@@ -86,6 +91,7 @@ export const createPage = async (
8691
app,
8792
content,
8893
filePathRelative,
94+
frontmatter,
8995
htmlFilePathRelative,
9096
key,
9197
})

packages/@vuepress/core/src/page/resolvePageComponentInfo.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,22 @@ import type {
44
MarkdownLink,
55
} from '@vuepress/markdown'
66
import { path } from '@vuepress/utils'
7-
import type { App } from '../types'
7+
import type { App, PageFrontmatter } from '../types'
88

99
/**
1010
* Resolve page component and related info
1111
*/
1212
export const resolvePageComponentInfo = async ({
1313
app,
1414
content,
15+
frontmatter,
1516
filePathRelative,
1617
htmlFilePathRelative,
1718
key,
1819
}: {
1920
app: App
2021
content: string
22+
frontmatter: PageFrontmatter
2123
filePathRelative: string | null
2224
htmlFilePathRelative: string | null
2325
key: string
@@ -32,6 +34,7 @@ export const resolvePageComponentInfo = async ({
3234
const markdownEnv: MarkdownEnv = {
3335
base: app.options.base,
3436
filePathRelative,
37+
frontmatter,
3538
}
3639

3740
const rendered = app.markdown.render(content, markdownEnv)

packages/@vuepress/core/src/page/resolvePageExcerpt.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
import type { MarkdownEnv } from '@vuepress/markdown'
2-
import type { App } from '../types'
2+
import type { App, PageFrontmatter } from '../types'
33

44
/**
55
* Resolve page excerpt from raw excerpt
66
*/
77
export const resolvePageExcerpt = ({
8-
excerptRaw,
98
app,
9+
excerptRaw,
10+
frontmatter,
1011
filePathRelative,
1112
}: {
12-
excerptRaw: string
1313
app: App
14+
excerptRaw: string
15+
frontmatter: PageFrontmatter
1416
filePathRelative: string | null
1517
}): string => {
1618
const markdownEnv: MarkdownEnv = {
1719
base: app.options.base,
1820
filePathRelative,
21+
frontmatter,
1922
}
2023
const html = app.markdown.render(excerptRaw, markdownEnv)
2124
return html

packages/@vuepress/markdown/src/types.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as MarkdownIt from 'markdown-it'
2-
import type { PageHeader } from '@vuepress/shared'
2+
import type { PageFrontmatter, PageHeader } from '@vuepress/shared'
33
import type {
44
AnchorPluginOptions,
55
AssetsPluginOptions,
@@ -61,6 +61,11 @@ export interface MarkdownEnv {
6161
*/
6262
filePathRelative?: string | null
6363

64+
/**
65+
* Frontmatter of the markdown file
66+
*/
67+
frontmatter?: PageFrontmatter
68+
6469
// Output
6570

6671
/**

0 commit comments

Comments
 (0)