From dbbffa2487cd1f9899916baa166591248fb24334 Mon Sep 17 00:00:00 2001 From: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> Date: Sat, 11 Nov 2023 15:01:42 +0530 Subject: [PATCH] fix(build): remove frontmatter in md file inclusion closes #3195 --- .../e2e/markdown-extensions/markdown-extensions.test.ts | 5 +++++ __tests__/e2e/markdown-extensions/nested-include.md | 4 ++++ src/node/utils/processIncludes.ts | 5 ++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/__tests__/e2e/markdown-extensions/markdown-extensions.test.ts b/__tests__/e2e/markdown-extensions/markdown-extensions.test.ts index b7ba5c19df03..aa1f6ff2a195 100644 --- a/__tests__/e2e/markdown-extensions/markdown-extensions.test.ts +++ b/__tests__/e2e/markdown-extensions/markdown-extensions.test.ts @@ -274,4 +274,9 @@ describe('Markdown File Inclusion', () => { expect(trim(await p.nth(0).textContent())).toBe('This is a region') expect(trim(await p.nth(1).textContent())).toBe('This is after region') }) + + test('ignore frontmatter if range is not specified', async () => { + const p = page.locator('.vp-doc') + expect(await p.textContent()).not.toContain('title') + }) }) diff --git a/__tests__/e2e/markdown-extensions/nested-include.md b/__tests__/e2e/markdown-extensions/nested-include.md index eb7eb718240d..8b876c7805a6 100644 --- a/__tests__/e2e/markdown-extensions/nested-include.md +++ b/__tests__/e2e/markdown-extensions/nested-include.md @@ -1,3 +1,7 @@ +--- +title: Nested Include +--- + ### After Foo diff --git a/src/node/utils/processIncludes.ts b/src/node/utils/processIncludes.ts index 43808ba4bbe6..0217769746c5 100644 --- a/src/node/utils/processIncludes.ts +++ b/src/node/utils/processIncludes.ts @@ -1,5 +1,6 @@ -import path from 'path' import fs from 'fs-extra' +import matter from 'gray-matter' +import path from 'path' import { slash } from '../shared' export function processIncludes( @@ -30,6 +31,8 @@ export function processIncludes( endLine ? parseInt(endLine, 10) : undefined ) .join('\n') + } else { + content = matter(content).content } includes.push(slash(includePath)) // recursively process includes in the content