Skip to content

Commit

Permalink
feat: include frontmatter in globals
Browse files Browse the repository at this point in the history
  • Loading branch information
kaytwo authored Mar 23, 2021
1 parent 7834948 commit 647f8a3
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
22 changes: 22 additions & 0 deletions packages/docusaurus-plugin-content-docs/src/__tests__/docs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
1 change: 1 addition & 0 deletions packages/docusaurus-plugin-content-docs/src/docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,5 +219,6 @@ export function processDocMetadata({
)
: undefined,
sidebar_label: sidebarLabel,
frontMatter: options.includeFrontMatterInGlobals ? frontMatter : undefined,
};
}
1 change: 1 addition & 0 deletions packages/docusaurus-plugin-content-docs/src/globalData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export function toGlobalDataDoc(doc: DocMetadata): GlobalDoc {
id: doc.unversionedId,
path: doc.permalink,
sidebar: doc.sidebar,
...(doc.frontMatter && {frontMatter: doc.frontMatter}),
};
}

Expand Down
8 changes: 8 additions & 0 deletions packages/docusaurus-plugin-content-docs/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export type MetadataOptions = {
editLocalizedFiles: boolean;
showLastUpdateTime?: boolean;
showLastUpdateAuthor?: boolean;
includeFrontMatterInGlobals?: boolean;
};

export type PathOptions = {
Expand Down Expand Up @@ -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;
Expand All @@ -142,6 +148,7 @@ export type DocMetadataBase = LastUpdateData & {
// eslint-disable-next-line camelcase
sidebar_label?: string;
editUrl?: string | null;
frontMatter?: FrontMatter;
};

export type DocNavLink = {
Expand Down Expand Up @@ -174,6 +181,7 @@ export type GlobalDoc = {
id: string;
path: string;
sidebar: string | undefined;
frontMatter?: FrontMatter;
};

export type GlobalVersion = {
Expand Down

0 comments on commit 647f8a3

Please sign in to comment.