diff --git a/packages/core/package.json b/packages/core/package.json index 819e1b8582..00bd8af469 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -35,8 +35,12 @@ "@vuepress/markdown": "workspace:*", "@vuepress/shared": "workspace:*", "@vuepress/utils": "workspace:*", + "lodash.omit": "^4.5.0", "vue": "^3.2.47" }, + "devDependencies": { + "@types/lodash.omit": "^4.5.7" + }, "publishConfig": { "access": "public" }, diff --git a/packages/core/src/page/renderPageContent.ts b/packages/core/src/page/renderPageContent.ts index e213249284..d99a8c6b00 100644 --- a/packages/core/src/page/renderPageContent.ts +++ b/packages/core/src/page/renderPageContent.ts @@ -4,6 +4,7 @@ import type { MarkdownLink, MarkdownSfcBlocks, } from '@vuepress/markdown' +import omit from 'lodash.omit' import type { App, PageFrontmatter, PageOptions } from '../types/index.js' /** @@ -55,19 +56,7 @@ export const renderPageContent = ({ 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 + ...extraMarkdownEnv } = markdownEnv return { @@ -76,7 +65,14 @@ export const renderPageContent = ({ frontmatter, headers, links, - markdownEnv: otherEnv, + markdownEnv: omit( + extraMarkdownEnv, + 'base', + 'content', + 'filePath', + 'filePathRelative', + 'frontmatter' + ), sfcBlocks, title: frontmatter.title ?? title, } diff --git a/packages/core/src/types/page.ts b/packages/core/src/types/page.ts index 5b04a924af..fa01216ace 100644 --- a/packages/core/src/types/page.ts +++ b/packages/core/src/types/page.ts @@ -42,6 +42,11 @@ export type Page< */ links: MarkdownLink[] + /** + * Markdown env object of the page + */ + markdownEnv: Record + /** * Path of the page that inferred from file path * @@ -74,11 +79,6 @@ export type Page< */ routeMeta: Record - /** - * Markdown Environment of the page - */ - markdownEnv: Record - /** * Extracted sfc blocks of the page */ diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ed8be93996..cd0fa3e050 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -533,17 +533,22 @@ importers: packages/core: specifiers: + '@types/lodash.omit': ^4.5.7 '@vuepress/client': workspace:* '@vuepress/markdown': workspace:* '@vuepress/shared': workspace:* '@vuepress/utils': workspace:* + lodash.omit: ^4.5.0 vue: ^3.2.47 dependencies: '@vuepress/client': link:../client '@vuepress/markdown': link:../markdown '@vuepress/shared': link:../shared '@vuepress/utils': link:../utils + lodash.omit: 4.5.0 vue: 3.2.47 + devDependencies: + '@types/lodash.omit': 4.5.7 packages/markdown: specifiers: @@ -2892,6 +2897,16 @@ packages: resolution: {integrity: sha512-HZQYqbiFVWufzCwexrvh694SOim8z2d+xJl5UNamcvQFejLY/2YUtzXHYi3cHdI7PMlS8ejH2slRAOJQ32aNbA==} dev: false + /@types/lodash.omit/4.5.7: + resolution: {integrity: sha512-6q6cNg0tQ6oTWjSM+BcYMBhan54P/gLqBldG4AuXd3nKr0oeVekWNS4VrNEu3BhCSDXtGapi7zjhnna0s03KpA==} + dependencies: + '@types/lodash': 4.14.191 + dev: true + + /@types/lodash/4.14.191: + resolution: {integrity: sha512-BdZ5BCCvho3EIXw6wUCXHe7rS53AIDPLE+JzwgT+OsJk53oBfbSmZZ7CX4VaRoN78N+TJpFi9QPlfIVNmJYWxQ==} + dev: true + /@types/markdown-it-emoji/2.0.2: resolution: {integrity: sha512-2ln8Wjbcj/0oRi/6VnuMeWEHHuK8uapFttvcLmDIe1GKCsFBLOLBX+D+xhDa9oWOQV0IpvxwrSfKKssAqqroog==} dependencies: @@ -7137,6 +7152,10 @@ packages: resolution: {integrity: sha512-GK3g5RPZWTRSeLSpgP8Xhra+pnjBC56q9FZYe1d5RN3TJ35dbkGy3YqBSMbyCrlbi+CM9Z3Jk5yTL7RCsqboyQ==} dev: true + /lodash.omit/4.5.0: + resolution: {integrity: sha512-XeqSp49hNGmlkj2EJlfrQFIzQ6lXdNro9sddtQzcJY8QaoC2GO0DT7xaIokHeyM+mIT0mPMlPvkYzg2xCuHdZg==} + dev: false + /lodash.snakecase/4.1.1: resolution: {integrity: sha512-QZ1d4xoBHYUeuouhEq3lk3Uq7ldgyFXGBhg04+oRLnIz8o9T65Eh+8YdroUwn846zchkA9yDsDl5CVVaV2nqYw==} dev: true