From 3bc55416ca8455509c3d32a5374fca93a406a6e7 Mon Sep 17 00:00:00 2001 From: Chris Kanich Date: Tue, 23 Mar 2021 05:42:15 +0000 Subject: [PATCH 1/6] feat: include frontmatter in globals --- .../src/__tests__/docs.test.ts | 22 +++++++++++++++++++ .../src/docs.ts | 1 + .../src/globalData.ts | 1 + .../src/options.ts | 4 ++++ .../src/types.ts | 8 +++++++ 5 files changed, 36 insertions(+) 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 5c1feb6b157d..6974642d3340 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 4902c08f9b58..51b3d5acb0eb 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 64ca58bd1115..826c168e972f 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/options.ts b/packages/docusaurus-plugin-content-docs/src/options.ts index e7f7bcb1c71b..4d4cb679dee2 100644 --- a/packages/docusaurus-plugin-content-docs/src/options.ts +++ b/packages/docusaurus-plugin-content-docs/src/options.ts @@ -38,6 +38,7 @@ export const DEFAULT_OPTIONS: Omit = { versions: {}, editCurrentVersion: false, editLocalizedFiles: false, + includeFrontMatterInGlobals: false, }; const VersionOptionsSchema = Joi.object({ @@ -54,6 +55,9 @@ export const OptionsSchema = Joi.object({ editUrl: Joi.alternatives().try(URISchema, Joi.function()), editCurrentVersion: Joi.boolean().default(DEFAULT_OPTIONS.editCurrentVersion), editLocalizedFiles: Joi.boolean().default(DEFAULT_OPTIONS.editLocalizedFiles), + includeFrontMatterInGlobals: Joi.boolean().default( + DEFAULT_OPTIONS.includeFrontMatterInGlobals, + ), routeBasePath: Joi.string() // '' not allowed, see https://github.com/facebook/docusaurus/issues/3374 // .allow('') "" diff --git a/packages/docusaurus-plugin-content-docs/src/types.ts b/packages/docusaurus-plugin-content-docs/src/types.ts index 7fb0f50c224f..abe65208a17a 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 = { From 29d3c532eccadcc7bc5c66c3871e20a7e20b769f Mon Sep 17 00:00:00 2001 From: Chris Kanich Date: Tue, 23 Mar 2021 07:22:51 +0000 Subject: [PATCH 2/6] feat: include frontmatter in globals (options schema test) --- .../docusaurus-plugin-content-docs/src/__tests__/options.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/options.test.ts b/packages/docusaurus-plugin-content-docs/src/__tests__/options.test.ts index fd1c61ddf0e5..7eefa12b2cb5 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/options.test.ts +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/options.test.ts @@ -40,6 +40,7 @@ describe('normalizeDocsPluginOptions', () => { disableVersioning: true, editCurrentVersion: true, editLocalizedFiles: true, + includeFrontMatterInGlobals: true, versions: { current: { path: 'next', From 6a2fb270ea3c019730aac7bd0c6e579f552a49a0 Mon Sep 17 00:00:00 2001 From: Chris Kanich Date: Thu, 25 Mar 2021 00:27:59 +0000 Subject: [PATCH 3/6] feat(v2): document frontmatter in document metadata --- .../src/__tests__/options.test.ts | 1 - packages/docusaurus-plugin-content-docs/src/docs.ts | 2 +- packages/docusaurus-plugin-content-docs/src/globalData.ts | 1 - packages/docusaurus-plugin-content-docs/src/options.ts | 4 ---- packages/docusaurus-plugin-content-docs/src/types.ts | 1 - 5 files changed, 1 insertion(+), 8 deletions(-) diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/options.test.ts b/packages/docusaurus-plugin-content-docs/src/__tests__/options.test.ts index 7eefa12b2cb5..fd1c61ddf0e5 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/options.test.ts +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/options.test.ts @@ -40,7 +40,6 @@ describe('normalizeDocsPluginOptions', () => { disableVersioning: true, editCurrentVersion: true, editLocalizedFiles: true, - includeFrontMatterInGlobals: true, versions: { current: { path: 'next', diff --git a/packages/docusaurus-plugin-content-docs/src/docs.ts b/packages/docusaurus-plugin-content-docs/src/docs.ts index 1868e48e5b45..592b99843999 100644 --- a/packages/docusaurus-plugin-content-docs/src/docs.ts +++ b/packages/docusaurus-plugin-content-docs/src/docs.ts @@ -219,6 +219,6 @@ export function processDocMetadata({ ) : undefined, sidebar_label: sidebarLabel, - frontMatter: options.includeFrontMatterInGlobals ? frontMatter : undefined, + frontMatter, }; } diff --git a/packages/docusaurus-plugin-content-docs/src/globalData.ts b/packages/docusaurus-plugin-content-docs/src/globalData.ts index 826c168e972f..64ca58bd1115 100644 --- a/packages/docusaurus-plugin-content-docs/src/globalData.ts +++ b/packages/docusaurus-plugin-content-docs/src/globalData.ts @@ -12,7 +12,6 @@ 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/options.ts b/packages/docusaurus-plugin-content-docs/src/options.ts index 4d4cb679dee2..e7f7bcb1c71b 100644 --- a/packages/docusaurus-plugin-content-docs/src/options.ts +++ b/packages/docusaurus-plugin-content-docs/src/options.ts @@ -38,7 +38,6 @@ export const DEFAULT_OPTIONS: Omit = { versions: {}, editCurrentVersion: false, editLocalizedFiles: false, - includeFrontMatterInGlobals: false, }; const VersionOptionsSchema = Joi.object({ @@ -55,9 +54,6 @@ export const OptionsSchema = Joi.object({ editUrl: Joi.alternatives().try(URISchema, Joi.function()), editCurrentVersion: Joi.boolean().default(DEFAULT_OPTIONS.editCurrentVersion), editLocalizedFiles: Joi.boolean().default(DEFAULT_OPTIONS.editLocalizedFiles), - includeFrontMatterInGlobals: Joi.boolean().default( - DEFAULT_OPTIONS.includeFrontMatterInGlobals, - ), routeBasePath: Joi.string() // '' not allowed, see https://github.com/facebook/docusaurus/issues/3374 // .allow('') "" diff --git a/packages/docusaurus-plugin-content-docs/src/types.ts b/packages/docusaurus-plugin-content-docs/src/types.ts index abe65208a17a..d4372a654b5f 100644 --- a/packages/docusaurus-plugin-content-docs/src/types.ts +++ b/packages/docusaurus-plugin-content-docs/src/types.ts @@ -53,7 +53,6 @@ export type MetadataOptions = { editLocalizedFiles: boolean; showLastUpdateTime?: boolean; showLastUpdateAuthor?: boolean; - includeFrontMatterInGlobals?: boolean; }; export type PathOptions = { From 82798ffa03cc40debbde82f588f09c69bb496580 Mon Sep 17 00:00:00 2001 From: Chris Kanich Date: Thu, 25 Mar 2021 01:54:26 +0000 Subject: [PATCH 4/6] feat(v2): frontmatter in metadata, tests updated --- .../__snapshots__/index.test.ts.snap | 143 +++++++++++++++--- .../src/__tests__/docs.test.ts | 61 +++++--- .../src/__tests__/index.test.ts | 17 +++ 3 files changed, 181 insertions(+), 40 deletions(-) diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/index.test.ts.snap b/packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/index.test.ts.snap index 83a63999a80b..6ed8d53aa1e2 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/index.test.ts.snap +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/index.test.ts.snap @@ -152,6 +152,11 @@ Object { \\"slug\\": \\"/foo/bar\\", \\"permalink\\": \\"/docs/foo/bar\\", \\"version\\": \\"current\\", + \\"frontMatter\\": { + \\"id\\": \\"bar\\", + \\"title\\": \\"Bar\\", + \\"description\\": \\"This is custom description\\" + }, \\"sidebar\\": \\"docs\\", \\"next\\": { \\"title\\": \\"baz\\", @@ -168,6 +173,11 @@ Object { \\"slug\\": \\"/foo/bazSlug.html\\", \\"permalink\\": \\"/docs/foo/bazSlug.html\\", \\"version\\": \\"current\\", + \\"frontMatter\\": { + \\"id\\": \\"baz\\", + \\"title\\": \\"baz\\", + \\"slug\\": \\"bazSlug.html\\" + }, \\"sidebar\\": \\"docs\\", \\"previous\\": { \\"title\\": \\"Bar\\", @@ -187,7 +197,10 @@ Object { \\"source\\": \\"@site/docs/headingAsTitle.md\\", \\"slug\\": \\"/headingAsTitle\\", \\"permalink\\": \\"/docs/headingAsTitle\\", - \\"version\\": \\"current\\" + \\"version\\": \\"current\\", + \\"frontMatter\\": { + \\"title\\": \\"My heading as title\\" + } }", "site-docs-hello-md-9df.json": "{ \\"unversionedId\\": \\"hello\\", @@ -199,6 +212,10 @@ Object { \\"slug\\": \\"/\\", \\"permalink\\": \\"/docs/\\", \\"version\\": \\"current\\", + \\"frontMatter\\": { + \\"id\\": \\"hello\\", + \\"title\\": \\"Hello, World !\\" + }, \\"sidebar\\": \\"docs\\", \\"previous\\": { \\"title\\": \\"baz\\", @@ -215,7 +232,10 @@ Object { \\"slug\\": \\"/ipsum\\", \\"permalink\\": \\"/docs/ipsum\\", \\"editUrl\\": null, - \\"version\\": \\"current\\" + \\"version\\": \\"current\\", + \\"frontMatter\\": { + \\"custom_edit_url\\": null + } }", "site-docs-lorem-md-b27.json": "{ \\"unversionedId\\": \\"lorem\\", @@ -227,7 +247,11 @@ Object { \\"slug\\": \\"/lorem\\", \\"permalink\\": \\"/docs/lorem\\", \\"editUrl\\": \\"https://github.com/customUrl/docs/lorem.md\\", - \\"version\\": \\"current\\" + \\"version\\": \\"current\\", + \\"frontMatter\\": { + \\"custom_edit_url\\": \\"https://github.com/customUrl/docs/lorem.md\\", + \\"unrelated_frontmatter\\": \\"won't be part of metadata\\" + } }", "site-docs-root-absolute-slug-md-db5.json": "{ \\"unversionedId\\": \\"rootAbsoluteSlug\\", @@ -238,7 +262,10 @@ Object { \\"source\\": \\"@site/docs/rootAbsoluteSlug.md\\", \\"slug\\": \\"/rootAbsoluteSlug\\", \\"permalink\\": \\"/docs/rootAbsoluteSlug\\", - \\"version\\": \\"current\\" + \\"version\\": \\"current\\", + \\"frontMatter\\": { + \\"slug\\": \\"/rootAbsoluteSlug\\" + } }", "site-docs-root-relative-slug-md-3dd.json": "{ \\"unversionedId\\": \\"rootRelativeSlug\\", @@ -249,7 +276,10 @@ Object { \\"source\\": \\"@site/docs/rootRelativeSlug.md\\", \\"slug\\": \\"/rootRelativeSlug\\", \\"permalink\\": \\"/docs/rootRelativeSlug\\", - \\"version\\": \\"current\\" + \\"version\\": \\"current\\", + \\"frontMatter\\": { + \\"slug\\": \\"rootRelativeSlug\\" + } }", "site-docs-root-resolved-slug-md-4d1.json": "{ \\"unversionedId\\": \\"rootResolvedSlug\\", @@ -260,7 +290,10 @@ Object { \\"source\\": \\"@site/docs/rootResolvedSlug.md\\", \\"slug\\": \\"/hey/rootResolvedSlug\\", \\"permalink\\": \\"/docs/hey/rootResolvedSlug\\", - \\"version\\": \\"current\\" + \\"version\\": \\"current\\", + \\"frontMatter\\": { + \\"slug\\": \\"./hey/ho/../rootResolvedSlug\\" + } }", "site-docs-root-try-to-escape-slug-md-9ee.json": "{ \\"unversionedId\\": \\"rootTryToEscapeSlug\\", @@ -271,7 +304,10 @@ Object { \\"source\\": \\"@site/docs/rootTryToEscapeSlug.md\\", \\"slug\\": \\"/rootTryToEscapeSlug\\", \\"permalink\\": \\"/docs/rootTryToEscapeSlug\\", - \\"version\\": \\"current\\" + \\"version\\": \\"current\\", + \\"frontMatter\\": { + \\"slug\\": \\"../../../../../../../../rootTryToEscapeSlug\\" + } }", "site-docs-slugs-absolute-slug-md-4e8.json": "{ \\"unversionedId\\": \\"slugs/absoluteSlug\\", @@ -282,7 +318,10 @@ Object { \\"source\\": \\"@site/docs/slugs/absoluteSlug.md\\", \\"slug\\": \\"/absoluteSlug\\", \\"permalink\\": \\"/docs/absoluteSlug\\", - \\"version\\": \\"current\\" + \\"version\\": \\"current\\", + \\"frontMatter\\": { + \\"slug\\": \\"/absoluteSlug\\" + } }", "site-docs-slugs-relative-slug-md-d1c.json": "{ \\"unversionedId\\": \\"slugs/relativeSlug\\", @@ -293,7 +332,10 @@ Object { \\"source\\": \\"@site/docs/slugs/relativeSlug.md\\", \\"slug\\": \\"/slugs/relativeSlug\\", \\"permalink\\": \\"/docs/slugs/relativeSlug\\", - \\"version\\": \\"current\\" + \\"version\\": \\"current\\", + \\"frontMatter\\": { + \\"slug\\": \\"relativeSlug\\" + } }", "site-docs-slugs-resolved-slug-md-02b.json": "{ \\"unversionedId\\": \\"slugs/resolvedSlug\\", @@ -304,7 +346,10 @@ Object { \\"source\\": \\"@site/docs/slugs/resolvedSlug.md\\", \\"slug\\": \\"/slugs/hey/resolvedSlug\\", \\"permalink\\": \\"/docs/slugs/hey/resolvedSlug\\", - \\"version\\": \\"current\\" + \\"version\\": \\"current\\", + \\"frontMatter\\": { + \\"slug\\": \\"./hey/ho/../resolvedSlug\\" + } }", "site-docs-slugs-try-to-escape-slug-md-70d.json": "{ \\"unversionedId\\": \\"slugs/tryToEscapeSlug\\", @@ -315,7 +360,10 @@ Object { \\"source\\": \\"@site/docs/slugs/tryToEscapeSlug.md\\", \\"slug\\": \\"/tryToEscapeSlug\\", \\"permalink\\": \\"/docs/tryToEscapeSlug\\", - \\"version\\": \\"current\\" + \\"version\\": \\"current\\", + \\"frontMatter\\": { + \\"slug\\": \\"../../../../../../../../tryToEscapeSlug\\" + } }", "version-current-metadata-prop-751.json": "{ \\"pluginId\\": \\"default\\", @@ -656,6 +704,7 @@ Object { \\"slug\\": \\"/team\\", \\"permalink\\": \\"/community/team\\", \\"version\\": \\"1.0.0\\", + \\"frontMatter\\": {}, \\"sidebar\\": \\"version-1.0.0/community\\" }", "site-i-18-n-en-docusaurus-plugin-content-docs-community-current-team-md-7e5.json": "{ @@ -668,6 +717,9 @@ Object { \\"slug\\": \\"/team\\", \\"permalink\\": \\"/community/next/team\\", \\"version\\": \\"current\\", + \\"frontMatter\\": { + \\"title\\": \\"Team title translated\\" + }, \\"sidebar\\": \\"community\\" }", "version-1-0-0-metadata-prop-608.json": "{ @@ -895,6 +947,9 @@ Object { \\"slug\\": \\"/foo/barSlug\\", \\"permalink\\": \\"/docs/next/foo/barSlug\\", \\"version\\": \\"current\\", + \\"frontMatter\\": { + \\"slug\\": \\"barSlug\\" + }, \\"sidebar\\": \\"docs\\", \\"next\\": { \\"title\\": \\"hello\\", @@ -911,6 +966,7 @@ Object { \\"slug\\": \\"/\\", \\"permalink\\": \\"/docs/next/\\", \\"version\\": \\"current\\", + \\"frontMatter\\": {}, \\"sidebar\\": \\"docs\\", \\"previous\\": { \\"title\\": \\"bar\\", @@ -926,7 +982,10 @@ Object { \\"source\\": \\"@site/docs/slugs/absoluteSlug.md\\", \\"slug\\": \\"/absoluteSlug\\", \\"permalink\\": \\"/docs/next/absoluteSlug\\", - \\"version\\": \\"current\\" + \\"version\\": \\"current\\", + \\"frontMatter\\": { + \\"slug\\": \\"/absoluteSlug\\" + } }", "site-docs-slugs-relative-slug-md-d1c.json": "{ \\"unversionedId\\": \\"slugs/relativeSlug\\", @@ -937,7 +996,10 @@ Object { \\"source\\": \\"@site/docs/slugs/relativeSlug.md\\", \\"slug\\": \\"/slugs/relativeSlug\\", \\"permalink\\": \\"/docs/next/slugs/relativeSlug\\", - \\"version\\": \\"current\\" + \\"version\\": \\"current\\", + \\"frontMatter\\": { + \\"slug\\": \\"relativeSlug\\" + } }", "site-docs-slugs-resolved-slug-md-02b.json": "{ \\"unversionedId\\": \\"slugs/resolvedSlug\\", @@ -948,7 +1010,10 @@ Object { \\"source\\": \\"@site/docs/slugs/resolvedSlug.md\\", \\"slug\\": \\"/slugs/hey/resolvedSlug\\", \\"permalink\\": \\"/docs/next/slugs/hey/resolvedSlug\\", - \\"version\\": \\"current\\" + \\"version\\": \\"current\\", + \\"frontMatter\\": { + \\"slug\\": \\"./hey/ho/../resolvedSlug\\" + } }", "site-docs-slugs-try-to-escape-slug-md-70d.json": "{ \\"unversionedId\\": \\"slugs/tryToEscapeSlug\\", @@ -959,7 +1024,10 @@ Object { \\"source\\": \\"@site/docs/slugs/tryToEscapeSlug.md\\", \\"slug\\": \\"/tryToEscapeSlug\\", \\"permalink\\": \\"/docs/next/tryToEscapeSlug\\", - \\"version\\": \\"current\\" + \\"version\\": \\"current\\", + \\"frontMatter\\": { + \\"slug\\": \\"../../../../../../../../tryToEscapeSlug\\" + } }", "site-i-18-n-en-docusaurus-plugin-content-docs-version-1-0-0-hello-md-fe5.json": "{ \\"unversionedId\\": \\"hello\\", @@ -971,6 +1039,7 @@ Object { \\"slug\\": \\"/\\", \\"permalink\\": \\"/docs/1.0.0/\\", \\"version\\": \\"1.0.0\\", + \\"frontMatter\\": {}, \\"sidebar\\": \\"version-1.0.0/docs\\", \\"previous\\": { \\"title\\": \\"baz\\", @@ -987,6 +1056,9 @@ Object { \\"slug\\": \\"/foo/barSlug\\", \\"permalink\\": \\"/docs/1.0.0/foo/barSlug\\", \\"version\\": \\"1.0.0\\", + \\"frontMatter\\": { + \\"slug\\": \\"barSlug\\" + }, \\"sidebar\\": \\"version-1.0.0/docs\\", \\"next\\": { \\"title\\": \\"baz\\", @@ -1003,6 +1075,7 @@ Object { \\"slug\\": \\"/foo/baz\\", \\"permalink\\": \\"/docs/1.0.0/foo/baz\\", \\"version\\": \\"1.0.0\\", + \\"frontMatter\\": {}, \\"sidebar\\": \\"version-1.0.0/docs\\", \\"previous\\": { \\"title\\": \\"bar\\", @@ -1023,6 +1096,7 @@ Object { \\"slug\\": \\"/foo/bar\\", \\"permalink\\": \\"/docs/foo/bar\\", \\"version\\": \\"1.0.1\\", + \\"frontMatter\\": {}, \\"sidebar\\": \\"version-1.0.1/docs\\", \\"next\\": { \\"title\\": \\"hello\\", @@ -1039,6 +1113,7 @@ Object { \\"slug\\": \\"/\\", \\"permalink\\": \\"/docs/\\", \\"version\\": \\"1.0.1\\", + \\"frontMatter\\": {}, \\"sidebar\\": \\"version-1.0.1/docs\\", \\"previous\\": { \\"title\\": \\"bar\\", @@ -1055,6 +1130,9 @@ Object { \\"slug\\": \\"/rootAbsoluteSlug\\", \\"permalink\\": \\"/docs/withSlugs/rootAbsoluteSlug\\", \\"version\\": \\"withSlugs\\", + \\"frontMatter\\": { + \\"slug\\": \\"/rootAbsoluteSlug\\" + }, \\"sidebar\\": \\"version-1.0.1/docs\\" }", "site-versioned-docs-version-with-slugs-root-relative-slug-md-32a.json": "{ @@ -1066,7 +1144,10 @@ Object { \\"source\\": \\"@site/versioned_docs/version-withSlugs/rootRelativeSlug.md\\", \\"slug\\": \\"/rootRelativeSlug\\", \\"permalink\\": \\"/docs/withSlugs/rootRelativeSlug\\", - \\"version\\": \\"withSlugs\\" + \\"version\\": \\"withSlugs\\", + \\"frontMatter\\": { + \\"slug\\": \\"rootRelativeSlug\\" + } }", "site-versioned-docs-version-with-slugs-root-resolved-slug-md-aee.json": "{ \\"unversionedId\\": \\"rootResolvedSlug\\", @@ -1077,7 +1158,10 @@ Object { \\"source\\": \\"@site/versioned_docs/version-withSlugs/rootResolvedSlug.md\\", \\"slug\\": \\"/hey/rootResolvedSlug\\", \\"permalink\\": \\"/docs/withSlugs/hey/rootResolvedSlug\\", - \\"version\\": \\"withSlugs\\" + \\"version\\": \\"withSlugs\\", + \\"frontMatter\\": { + \\"slug\\": \\"./hey/ho/../rootResolvedSlug\\" + } }", "site-versioned-docs-version-with-slugs-root-try-to-escape-slug-md-b5d.json": "{ \\"unversionedId\\": \\"rootTryToEscapeSlug\\", @@ -1088,7 +1172,10 @@ Object { \\"source\\": \\"@site/versioned_docs/version-withSlugs/rootTryToEscapeSlug.md\\", \\"slug\\": \\"/rootTryToEscapeSlug\\", \\"permalink\\": \\"/docs/withSlugs/rootTryToEscapeSlug\\", - \\"version\\": \\"withSlugs\\" + \\"version\\": \\"withSlugs\\", + \\"frontMatter\\": { + \\"slug\\": \\"../../../../../../../../rootTryToEscapeSlug\\" + } }", "site-versioned-docs-version-with-slugs-slugs-absolute-slug-md-47a.json": "{ \\"unversionedId\\": \\"slugs/absoluteSlug\\", @@ -1099,7 +1186,10 @@ Object { \\"source\\": \\"@site/versioned_docs/version-withSlugs/slugs/absoluteSlug.md\\", \\"slug\\": \\"/absoluteSlug\\", \\"permalink\\": \\"/docs/withSlugs/absoluteSlug\\", - \\"version\\": \\"withSlugs\\" + \\"version\\": \\"withSlugs\\", + \\"frontMatter\\": { + \\"slug\\": \\"/absoluteSlug\\" + } }", "site-versioned-docs-version-with-slugs-slugs-relative-slug-md-a95.json": "{ \\"unversionedId\\": \\"slugs/relativeSlug\\", @@ -1110,7 +1200,10 @@ Object { \\"source\\": \\"@site/versioned_docs/version-withSlugs/slugs/relativeSlug.md\\", \\"slug\\": \\"/slugs/relativeSlug\\", \\"permalink\\": \\"/docs/withSlugs/slugs/relativeSlug\\", - \\"version\\": \\"withSlugs\\" + \\"version\\": \\"withSlugs\\", + \\"frontMatter\\": { + \\"slug\\": \\"relativeSlug\\" + } }", "site-versioned-docs-version-with-slugs-slugs-resolved-slug-md-5a1.json": "{ \\"unversionedId\\": \\"slugs/resolvedSlug\\", @@ -1121,7 +1214,10 @@ Object { \\"source\\": \\"@site/versioned_docs/version-withSlugs/slugs/resolvedSlug.md\\", \\"slug\\": \\"/slugs/hey/resolvedSlug\\", \\"permalink\\": \\"/docs/withSlugs/slugs/hey/resolvedSlug\\", - \\"version\\": \\"withSlugs\\" + \\"version\\": \\"withSlugs\\", + \\"frontMatter\\": { + \\"slug\\": \\"./hey/ho/../resolvedSlug\\" + } }", "site-versioned-docs-version-with-slugs-slugs-try-to-escape-slug-md-4e1.json": "{ \\"unversionedId\\": \\"slugs/tryToEscapeSlug\\", @@ -1132,7 +1228,10 @@ Object { \\"source\\": \\"@site/versioned_docs/version-withSlugs/slugs/tryToEscapeSlug.md\\", \\"slug\\": \\"/tryToEscapeSlug\\", \\"permalink\\": \\"/docs/withSlugs/tryToEscapeSlug\\", - \\"version\\": \\"withSlugs\\" + \\"version\\": \\"withSlugs\\", + \\"frontMatter\\": { + \\"slug\\": \\"../../../../../../../../tryToEscapeSlug\\" + } }", "version-1-0-0-metadata-prop-608.json": "{ \\"pluginId\\": \\"default\\", 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 a0fb351619be..0ffdeb37792c 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/docs.test.ts +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/docs.test.ts @@ -182,6 +182,11 @@ describe('simple site', () => { slug: '/foo/bar', title: 'Bar', description: 'This is custom description', + frontMatter: { + description: 'This is custom description', + id: 'bar', + title: 'Bar', + }, }); await defaultTestUtils.testMeta(path.join('hello.md'), { version: 'current', @@ -192,6 +197,10 @@ describe('simple site', () => { slug: '/hello', title: 'Hello, World !', description: `Hi, Endilie here :)`, + frontMatter: { + id: 'hello', + title: 'Hello, World !', + }, }); }); @@ -216,6 +225,10 @@ describe('simple site', () => { slug: '/', title: 'Hello, World !', description: `Hi, Endilie here :)`, + frontMatter: { + id: 'hello', + title: 'Hello, World !', + }, }); }); @@ -240,6 +253,11 @@ describe('simple site', () => { slug: '/', title: 'Bar', description: 'This is custom description', + frontMatter: { + description: 'This is custom description', + id: 'bar', + title: 'Bar', + }, }); }); @@ -268,6 +286,11 @@ describe('simple site', () => { editUrl: 'https://github.com/facebook/docusaurus/edit/master/website/docs/foo/baz.md', description: 'Images', + frontMatter: { + id: 'baz', + slug: 'bazSlug.html', + title: 'baz', + }, }); }); @@ -284,28 +307,10 @@ describe('simple site', () => { title: 'lorem', editUrl: 'https://github.com/customUrl/docs/lorem.md', description: 'Lorem ipsum.', - }); - }); - - 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.', }); }); @@ -337,6 +342,11 @@ describe('simple site', () => { title: 'baz', editUrl: hardcodedEditUrl, description: 'Images', + frontMatter: { + id: 'baz', + slug: 'bazSlug.html', + title: 'baz', + }, }); expect(editUrlFunction).toHaveBeenCalledTimes(1); @@ -374,6 +384,10 @@ describe('simple site', () => { title: 'lorem', editUrl: 'https://github.com/customUrl/docs/lorem.md', description: 'Lorem ipsum.', + frontMatter: { + custom_edit_url: 'https://github.com/customUrl/docs/lorem.md', + unrelated_frontmatter: "won't be part of metadata", + }, lastUpdatedAt: 1539502055, formattedLastUpdatedAt: '10/14/2018', lastUpdatedBy: 'Author', @@ -540,6 +554,7 @@ describe('versioned site', () => { slug: '/foo/barSlug', title: 'bar', description: 'This is next version of bar.', + frontMatter: {slug: 'barSlug'}, version: 'current', }); await currentVersionTestUtils.testMeta(path.join('hello.md'), { @@ -550,6 +565,7 @@ describe('versioned site', () => { slug: '/hello', title: 'hello', description: 'Hello next !', + frontMatter: {}, version: 'current', }); }); @@ -565,6 +581,7 @@ describe('versioned site', () => { slug: '/foo/barSlug', title: 'bar', description: 'Bar 1.0.0 !', + frontMatter: {slug: 'barSlug'}, version: '1.0.0', }); await version100TestUtils.testMeta(path.join('hello.md'), { @@ -575,6 +592,7 @@ describe('versioned site', () => { slug: '/hello', title: 'hello', description: 'Hello 1.0.0 ! (translated en)', + frontMatter: {}, version: '1.0.0', source: '@site/i18n/en/docusaurus-plugin-content-docs/version-1.0.0/hello.md', @@ -588,6 +606,7 @@ describe('versioned site', () => { title: 'bar', description: 'Bar 1.0.1 !', version: '1.0.1', + frontMatter: {}, }); await version101TestUtils.testMeta(path.join('hello.md'), { id: 'version-1.0.1/hello', @@ -598,6 +617,7 @@ describe('versioned site', () => { title: 'hello', description: 'Hello 1.0.1 !', version: '1.0.1', + frontMatter: {}, }); }); @@ -686,6 +706,7 @@ describe('versioned site', () => { slug: '/hello', title: 'hello', description: 'Hello 1.0.0 ! (translated en)', + frontMatter: {}, version: '1.0.0', source: '@site/i18n/en/docusaurus-plugin-content-docs/version-1.0.0/hello.md', @@ -725,6 +746,7 @@ describe('versioned site', () => { slug: '/hello', title: 'hello', description: 'Hello 1.0.0 ! (translated en)', + frontMatter: {}, version: '1.0.0', source: '@site/i18n/en/docusaurus-plugin-content-docs/version-1.0.0/hello.md', @@ -756,6 +778,7 @@ describe('versioned site', () => { slug: '/hello', title: 'hello', description: 'Hello 1.0.0 ! (translated en)', + frontMatter: {}, version: '1.0.0', source: '@site/i18n/en/docusaurus-plugin-content-docs/version-1.0.0/hello.md', @@ -788,6 +811,7 @@ describe('versioned site', () => { slug: '/hello', title: 'hello', description: 'Hello 1.0.0 ! (translated fr)', + frontMatter: {}, version: '1.0.0', source: '@site/i18n/fr/docusaurus-plugin-content-docs/version-1.0.0/hello.md', @@ -821,6 +845,7 @@ describe('versioned site', () => { slug: '/hello', title: 'hello', description: 'Hello 1.0.0 ! (translated fr)', + frontMatter: {}, version: '1.0.0', source: '@site/i18n/fr/docusaurus-plugin-content-docs/version-1.0.0/hello.md', diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/index.test.ts b/packages/docusaurus-plugin-content-docs/src/__tests__/index.test.ts index 87dba280cb2e..cb5229224f4b 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/index.test.ts +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/index.test.ts @@ -262,6 +262,10 @@ describe('simple website', () => { ), title: 'Hello, World !', description: 'Hi, Endilie here :)', + frontMatter: { + id: 'hello', + title: 'Hello, World !', + }, }); expect(findDocById(currentVersion, 'foo/bar')).toEqual({ @@ -285,6 +289,11 @@ describe('simple website', () => { ), title: 'Bar', description: 'This is custom description', + frontMatter: { + description: 'This is custom description', + id: 'bar', + title: 'Bar', + }, }); expect(currentVersion.sidebars).toMatchSnapshot(); @@ -433,6 +442,9 @@ describe('versioned website', () => { ), title: 'bar', description: 'This is next version of bar.', + frontMatter: { + slug: 'barSlug', + }, version: 'current', sidebar: 'docs', next: { @@ -454,6 +466,7 @@ describe('versioned website', () => { ), title: 'hello', description: 'Hello next !', + frontMatter: {}, version: 'current', sidebar: 'docs', previous: { @@ -475,6 +488,7 @@ describe('versioned website', () => { ), title: 'hello', description: 'Hello 1.0.1 !', + frontMatter: {}, version: '1.0.1', sidebar: 'version-1.0.1/docs', previous: { @@ -498,6 +512,7 @@ describe('versioned website', () => { title: 'baz', description: 'Baz 1.0.0 ! This will be deleted in next subsequent versions.', + frontMatter: {}, version: '1.0.0', sidebar: 'version-1.0.0/docs', next: { @@ -642,6 +657,7 @@ describe('versioned website (community)', () => { description: 'Team current version (translated)', version: 'current', sidebar: 'community', + frontMatter: {title: 'Team title translated'}, }); expect(findDocById(version100, 'team')).toEqual({ ...defaultDocMetadata, @@ -659,6 +675,7 @@ describe('versioned website (community)', () => { description: 'Team 1.0.0', version: '1.0.0', sidebar: 'version-1.0.0/community', + frontMatter: {}, }); expect(currentVersion.sidebars).toMatchSnapshot('current version sidebars'); From ed9387aa71874b9b2497c198814f623d9301586d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lorber?= Date: Fri, 26 Mar 2021 19:43:15 +0100 Subject: [PATCH 5/6] Update packages/docusaurus-plugin-content-docs/src/types.ts --- packages/docusaurus-plugin-content-docs/src/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/docusaurus-plugin-content-docs/src/types.ts b/packages/docusaurus-plugin-content-docs/src/types.ts index d4372a654b5f..e815d294eeff 100644 --- a/packages/docusaurus-plugin-content-docs/src/types.ts +++ b/packages/docusaurus-plugin-content-docs/src/types.ts @@ -147,7 +147,7 @@ export type DocMetadataBase = LastUpdateData & { // eslint-disable-next-line camelcase sidebar_label?: string; editUrl?: string | null; - frontMatter?: FrontMatter; + frontMatter: FrontMatter; }; export type DocNavLink = { From 8b4cbdc578f4155a2a17659e65e9aa65b6f221d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lorber?= Date: Fri, 26 Mar 2021 19:44:28 +0100 Subject: [PATCH 6/6] Update packages/docusaurus-plugin-content-docs/src/types.ts --- packages/docusaurus-plugin-content-docs/src/types.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/docusaurus-plugin-content-docs/src/types.ts b/packages/docusaurus-plugin-content-docs/src/types.ts index e815d294eeff..bf5628d0e8de 100644 --- a/packages/docusaurus-plugin-content-docs/src/types.ts +++ b/packages/docusaurus-plugin-content-docs/src/types.ts @@ -180,7 +180,6 @@ export type GlobalDoc = { id: string; path: string; sidebar: string | undefined; - frontMatter?: FrontMatter; }; export type GlobalVersion = {