diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/docs.test.ts b/packages/docusaurus-plugin-content-docs/src/__tests__/docs.test.ts index 5c1feb6b157d3..6974642d33406 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/docs.test.ts +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/docs.test.ts @@ -286,6 +286,28 @@ describe('simple site', () => { }); }); + test('docs with custom editUrl & including unrelated frontmatter in globals', async () => { + const {defaultTestUtils} = await loadSite({ + options: {includeFrontMatterInGlobals: true}, + }); + + await defaultTestUtils.testMeta('lorem.md', { + version: 'current', + id: 'lorem', + unversionedId: 'lorem', + isDocsHomePage: false, + permalink: '/docs/lorem', + slug: '/lorem', + title: 'lorem', + editUrl: 'https://github.com/customUrl/docs/lorem.md', + frontMatter: { + custom_edit_url: 'https://github.com/customUrl/docs/lorem.md', + unrelated_frontmatter: "won't be part of metadata", + }, + description: 'Lorem ipsum.', + }); + }); + test('docs with function editUrl', async () => { const hardcodedEditUrl = 'hardcoded-edit-url'; diff --git a/packages/docusaurus-plugin-content-docs/src/docs.ts b/packages/docusaurus-plugin-content-docs/src/docs.ts index 4902c08f9b580..51b3d5acb0eba 100644 --- a/packages/docusaurus-plugin-content-docs/src/docs.ts +++ b/packages/docusaurus-plugin-content-docs/src/docs.ts @@ -219,5 +219,6 @@ export function processDocMetadata({ ) : undefined, sidebar_label: sidebarLabel, + frontMatter: options.includeFrontMatterInGlobals ? frontMatter : undefined, }; } diff --git a/packages/docusaurus-plugin-content-docs/src/globalData.ts b/packages/docusaurus-plugin-content-docs/src/globalData.ts index 64ca58bd11151..826c168e972fe 100644 --- a/packages/docusaurus-plugin-content-docs/src/globalData.ts +++ b/packages/docusaurus-plugin-content-docs/src/globalData.ts @@ -12,6 +12,7 @@ export function toGlobalDataDoc(doc: DocMetadata): GlobalDoc { id: doc.unversionedId, path: doc.permalink, sidebar: doc.sidebar, + ...(doc.frontMatter && {frontMatter: doc.frontMatter}), }; } diff --git a/packages/docusaurus-plugin-content-docs/src/types.ts b/packages/docusaurus-plugin-content-docs/src/types.ts index 7fb0f50c224f9..abe65208a17ad 100644 --- a/packages/docusaurus-plugin-content-docs/src/types.ts +++ b/packages/docusaurus-plugin-content-docs/src/types.ts @@ -53,6 +53,7 @@ export type MetadataOptions = { editLocalizedFiles: boolean; showLastUpdateTime?: boolean; showLastUpdateAuthor?: boolean; + includeFrontMatterInGlobals?: boolean; }; export type PathOptions = { @@ -129,6 +130,11 @@ export type LastUpdateData = { lastUpdatedBy?: string; }; +export type FrontMatter = { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + [key: string]: any; +}; + export type DocMetadataBase = LastUpdateData & { version: VersionName; unversionedId: string; @@ -142,6 +148,7 @@ export type DocMetadataBase = LastUpdateData & { // eslint-disable-next-line camelcase sidebar_label?: string; editUrl?: string | null; + frontMatter?: FrontMatter; }; export type DocNavLink = { @@ -174,6 +181,7 @@ export type GlobalDoc = { id: string; path: string; sidebar: string | undefined; + frontMatter?: FrontMatter; }; export type GlobalVersion = {