diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/docs.test.ts.snap b/packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/docs.test.ts.snap index dce8065faf05..eaed1c90bbbb 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/docs.test.ts.snap +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/docs.test.ts.snap @@ -5,22 +5,11 @@ exports[`simple site custom pagination 1`] = ` "pagination": [ { "id": "doc with space", - "next": { - "permalink": "/docs/draft", - "title": "draft", - }, - "prev": undefined, - }, - { - "id": "draft", "next": { "permalink": "/docs/foo/bar", "title": "Bar", }, - "prev": { - "permalink": "/docs/doc with space", - "title": "Hoo hoo, if this path tricks you...", - }, + "prev": undefined, }, { "id": "foo/bar", @@ -174,10 +163,6 @@ exports[`simple site custom pagination 1`] = ` "id": "doc with space", "type": "doc", }, - { - "id": "draft", - "type": "doc", - }, { "collapsed": false, "collapsible": true, 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 4a0a4be2984c..635c832d3605 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 @@ -43,7 +43,6 @@ Available document ids are: exports[`simple website content 1`] = ` { "description": "Images", - "draft": false, "editUrl": undefined, "formattedLastUpdatedAt": undefined, "frontMatter": { @@ -96,7 +95,6 @@ exports[`simple website content 1`] = ` exports[`simple website content 2`] = ` { "description": "Hi, Endilie here :)", - "draft": false, "editUrl": undefined, "formattedLastUpdatedAt": undefined, "frontMatter": { @@ -142,7 +140,6 @@ exports[`simple website content 2`] = ` exports[`simple website content 3`] = ` { "description": "This is custom description", - "draft": false, "editUrl": undefined, "formattedLastUpdatedAt": undefined, "frontMatter": { @@ -401,8 +398,7 @@ exports[`simple website content: data 1`] = ` \\"permalink\\": \\"/docs/doc with space\\", \\"tags\\": [], \\"version\\": \\"current\\", - \\"frontMatter\\": {}, - \\"draft\\": false + \\"frontMatter\\": {} }", "site-docs-draft-md-5b1.json": "{ \\"unversionedId\\": \\"draft\\", @@ -417,8 +413,7 @@ exports[`simple website content: data 1`] = ` \\"version\\": \\"current\\", \\"frontMatter\\": { \\"draft\\": true - }, - \\"draft\\": false + } }", "site-docs-foo-bar-md-8c2.json": "{ \\"unversionedId\\": \\"foo/bar\\", @@ -438,7 +433,6 @@ exports[`simple website content: data 1`] = ` \\"pagination_next\\": null, \\"pagination_prev\\": null }, - \\"draft\\": false, \\"sidebar\\": \\"docs\\" }", "site-docs-foo-baz-md-a69.json": "{ @@ -475,7 +469,6 @@ exports[`simple website content: data 1`] = ` } ] }, - \\"draft\\": false, \\"sidebar\\": \\"docs\\", \\"previous\\": { \\"title\\": \\"Bar\\", @@ -498,7 +491,6 @@ exports[`simple website content: data 1`] = ` \\"tags\\": [], \\"version\\": \\"current\\", \\"frontMatter\\": {}, - \\"draft\\": false, \\"sidebar\\": \\"docs\\", \\"previous\\": { \\"title\\": \\"rootTryToEscapeSlug\\", @@ -539,7 +531,6 @@ exports[`simple website content: data 1`] = ` ], \\"slug\\": \\"/\\" }, - \\"draft\\": false, \\"sidebar\\": \\"docs\\", \\"previous\\": { \\"title\\": \\"My heading as title\\", @@ -560,8 +551,7 @@ exports[`simple website content: data 1`] = ` \\"version\\": \\"current\\", \\"frontMatter\\": { \\"custom_edit_url\\": null - }, - \\"draft\\": false + } }", "site-docs-lorem-md-b27.json": "{ \\"unversionedId\\": \\"lorem\\", @@ -578,8 +568,7 @@ exports[`simple website content: data 1`] = ` \\"frontMatter\\": { \\"custom_edit_url\\": \\"https://github.com/customUrl/docs/lorem.md\\", \\"unrelated_front_matter\\": \\"won't be part of metadata\\" - }, - \\"draft\\": false + } }", "site-docs-root-absolute-slug-md-db5.json": "{ \\"unversionedId\\": \\"rootAbsoluteSlug\\", @@ -597,7 +586,6 @@ exports[`simple website content: data 1`] = ` \\"pagination_next\\": \\"headingAsTitle\\", \\"pagination_prev\\": \\"foo/baz\\" }, - \\"draft\\": false, \\"sidebar\\": \\"docs\\", \\"previous\\": { \\"title\\": \\"baz pagination_label\\", @@ -624,7 +612,6 @@ exports[`simple website content: data 1`] = ` \\"pagination_next\\": \\"headingAsTitle\\", \\"pagination_prev\\": \\"foo/baz\\" }, - \\"draft\\": false, \\"sidebar\\": \\"docs\\", \\"previous\\": { \\"title\\": \\"baz pagination_label\\", @@ -651,7 +638,6 @@ exports[`simple website content: data 1`] = ` \\"pagination_next\\": \\"headingAsTitle\\", \\"pagination_prev\\": \\"foo/baz\\" }, - \\"draft\\": false, \\"sidebar\\": \\"docs\\", \\"previous\\": { \\"title\\": \\"baz pagination_label\\", @@ -678,7 +664,6 @@ exports[`simple website content: data 1`] = ` \\"pagination_next\\": \\"headingAsTitle\\", \\"pagination_prev\\": \\"foo/baz\\" }, - \\"draft\\": false, \\"sidebar\\": \\"docs\\", \\"previous\\": { \\"title\\": \\"baz pagination_label\\", @@ -702,8 +687,7 @@ exports[`simple website content: data 1`] = ` \\"version\\": \\"current\\", \\"frontMatter\\": { \\"slug\\": \\"/absoluteSlug\\" - }, - \\"draft\\": false + } }", "site-docs-slugs-relative-slug-md-d1c.json": "{ \\"unversionedId\\": \\"slugs/relativeSlug\\", @@ -718,8 +702,7 @@ exports[`simple website content: data 1`] = ` \\"version\\": \\"current\\", \\"frontMatter\\": { \\"slug\\": \\"relativeSlug\\" - }, - \\"draft\\": false + } }", "site-docs-slugs-resolved-slug-md-02b.json": "{ \\"unversionedId\\": \\"slugs/resolvedSlug\\", @@ -734,8 +717,7 @@ exports[`simple website content: data 1`] = ` \\"version\\": \\"current\\", \\"frontMatter\\": { \\"slug\\": \\"./hey/ho/../resolvedSlug\\" - }, - \\"draft\\": false + } }", "site-docs-slugs-try-to-escape-slug-md-70d.json": "{ \\"unversionedId\\": \\"slugs/tryToEscapeSlug\\", @@ -750,8 +732,7 @@ exports[`simple website content: data 1`] = ` \\"version\\": \\"current\\", \\"frontMatter\\": { \\"slug\\": \\"../../../../../../../../tryToEscapeSlug\\" - }, - \\"draft\\": false + } }", "tag-docs-tags-tag-1-b3f.json": "{ \\"name\\": \\"tag 1\\", @@ -1617,7 +1598,6 @@ exports[`site with custom sidebar items generator sidebarItemsGenerator is calle exports[`site with full autogenerated sidebar docs in fully generated sidebar have correct metadata 1`] = ` { "description": "Getting started text", - "draft": false, "editUrl": undefined, "formattedLastUpdatedAt": undefined, "frontMatter": {}, @@ -1645,7 +1625,6 @@ exports[`site with full autogenerated sidebar docs in fully generated sidebar ha exports[`site with full autogenerated sidebar docs in fully generated sidebar have correct metadata 2`] = ` { "description": "Installation text", - "draft": false, "editUrl": undefined, "formattedLastUpdatedAt": undefined, "frontMatter": {}, @@ -1676,7 +1655,6 @@ exports[`site with full autogenerated sidebar docs in fully generated sidebar ha exports[`site with full autogenerated sidebar docs in fully generated sidebar have correct metadata 3`] = ` { "description": "Guide 1 text", - "draft": false, "editUrl": undefined, "formattedLastUpdatedAt": undefined, "frontMatter": { @@ -1710,7 +1688,6 @@ exports[`site with full autogenerated sidebar docs in fully generated sidebar ha exports[`site with full autogenerated sidebar docs in fully generated sidebar have correct metadata 4`] = ` { "description": "Guide 2 text", - "draft": false, "editUrl": undefined, "formattedLastUpdatedAt": undefined, "frontMatter": { @@ -1743,7 +1720,6 @@ exports[`site with full autogenerated sidebar docs in fully generated sidebar ha exports[`site with full autogenerated sidebar docs in fully generated sidebar have correct metadata 5`] = ` { "description": "Guide 2.5 text", - "draft": false, "editUrl": undefined, "formattedLastUpdatedAt": undefined, "frontMatter": { @@ -1777,7 +1753,6 @@ exports[`site with full autogenerated sidebar docs in fully generated sidebar ha exports[`site with full autogenerated sidebar docs in fully generated sidebar have correct metadata 6`] = ` { "description": "Guide 3 text", - "draft": false, "editUrl": undefined, "formattedLastUpdatedAt": undefined, "frontMatter": { @@ -1811,7 +1786,6 @@ exports[`site with full autogenerated sidebar docs in fully generated sidebar ha exports[`site with full autogenerated sidebar docs in fully generated sidebar have correct metadata 7`] = ` { "description": "Guide 4 text", - "draft": false, "editUrl": undefined, "formattedLastUpdatedAt": undefined, "frontMatter": { @@ -1844,7 +1818,6 @@ exports[`site with full autogenerated sidebar docs in fully generated sidebar ha exports[`site with full autogenerated sidebar docs in fully generated sidebar have correct metadata 8`] = ` { "description": "Guide 5 text", - "draft": false, "editUrl": undefined, "formattedLastUpdatedAt": undefined, "frontMatter": { @@ -1877,7 +1850,6 @@ exports[`site with full autogenerated sidebar docs in fully generated sidebar ha exports[`site with full autogenerated sidebar docs in fully generated sidebar have correct metadata 9`] = ` { "description": "API Overview text", - "draft": false, "editUrl": undefined, "formattedLastUpdatedAt": undefined, "frontMatter": {}, @@ -1908,7 +1880,6 @@ exports[`site with full autogenerated sidebar docs in fully generated sidebar ha exports[`site with full autogenerated sidebar docs in fully generated sidebar have correct metadata 10`] = ` { "description": "Client API text", - "draft": false, "editUrl": undefined, "formattedLastUpdatedAt": undefined, "frontMatter": {}, @@ -1939,7 +1910,6 @@ exports[`site with full autogenerated sidebar docs in fully generated sidebar ha exports[`site with full autogenerated sidebar docs in fully generated sidebar have correct metadata 11`] = ` { "description": "Server API text", - "draft": false, "editUrl": undefined, "formattedLastUpdatedAt": undefined, "frontMatter": {}, @@ -1970,7 +1940,6 @@ exports[`site with full autogenerated sidebar docs in fully generated sidebar ha exports[`site with full autogenerated sidebar docs in fully generated sidebar have correct metadata 12`] = ` { "description": "Plugin API text", - "draft": false, "editUrl": undefined, "formattedLastUpdatedAt": undefined, "frontMatter": {}, @@ -2001,7 +1970,6 @@ exports[`site with full autogenerated sidebar docs in fully generated sidebar ha exports[`site with full autogenerated sidebar docs in fully generated sidebar have correct metadata 13`] = ` { "description": "Theme API text", - "draft": false, "editUrl": undefined, "formattedLastUpdatedAt": undefined, "frontMatter": {}, @@ -2032,7 +2000,6 @@ exports[`site with full autogenerated sidebar docs in fully generated sidebar ha exports[`site with full autogenerated sidebar docs in fully generated sidebar have correct metadata 14`] = ` { "description": "API End text", - "draft": false, "editUrl": undefined, "formattedLastUpdatedAt": undefined, "frontMatter": {}, @@ -2212,7 +2179,6 @@ exports[`site with partial autogenerated sidebars 2 (fix #4638) sidebar is parti exports[`site with partial autogenerated sidebars docs in partially generated sidebar have correct metadata 1`] = ` { "description": "API End text", - "draft": false, "editUrl": undefined, "formattedLastUpdatedAt": undefined, "frontMatter": {}, @@ -2240,7 +2206,6 @@ exports[`site with partial autogenerated sidebars docs in partially generated si exports[`site with partial autogenerated sidebars docs in partially generated sidebar have correct metadata 2`] = ` { "description": "API Overview text", - "draft": false, "editUrl": undefined, "formattedLastUpdatedAt": undefined, "frontMatter": {}, @@ -2271,7 +2236,6 @@ exports[`site with partial autogenerated sidebars docs in partially generated si exports[`site with partial autogenerated sidebars docs in partially generated sidebar have correct metadata 3`] = ` { "description": "Plugin API text", - "draft": false, "editUrl": undefined, "formattedLastUpdatedAt": undefined, "frontMatter": {}, @@ -2302,7 +2266,6 @@ exports[`site with partial autogenerated sidebars docs in partially generated si exports[`site with partial autogenerated sidebars docs in partially generated sidebar have correct metadata 4`] = ` { "description": "Theme API text", - "draft": false, "editUrl": undefined, "formattedLastUpdatedAt": undefined, "frontMatter": {}, @@ -2362,7 +2325,6 @@ exports[`site with partial autogenerated sidebars sidebar is partially autogener exports[`versioned website (community) content 1`] = ` { "description": "Team current version (translated)", - "draft": false, "editUrl": undefined, "formattedLastUpdatedAt": undefined, "frontMatter": { @@ -2389,7 +2351,6 @@ exports[`versioned website (community) content 1`] = ` exports[`versioned website (community) content 2`] = ` { "description": "Team 1.0.0", - "draft": false, "editUrl": undefined, "formattedLastUpdatedAt": undefined, "frontMatter": {}, @@ -2447,7 +2408,6 @@ exports[`versioned website (community) content: data 1`] = ` \\"tags\\": [], \\"version\\": \\"1.0.0\\", \\"frontMatter\\": {}, - \\"draft\\": false, \\"sidebar\\": \\"version-1.0.0/community\\" }", "site-i-18-n-en-docusaurus-plugin-content-docs-community-current-team-md-7e5.json": "{ @@ -2464,7 +2424,6 @@ exports[`versioned website (community) content: data 1`] = ` \\"frontMatter\\": { \\"title\\": \\"Team title translated\\" }, - \\"draft\\": false, \\"sidebar\\": \\"community\\" }", "version-1-0-0-metadata-prop-608.json": "{ @@ -2642,7 +2601,6 @@ exports[`versioned website (community) getPathToWatch 1`] = ` exports[`versioned website content 1`] = ` { "description": "This is next version of bar.", - "draft": false, "editUrl": undefined, "formattedLastUpdatedAt": undefined, "frontMatter": { @@ -2693,7 +2651,6 @@ exports[`versioned website content 1`] = ` exports[`versioned website content 2`] = ` { "description": "Bar 1.0.1 !", - "draft": false, "editUrl": undefined, "formattedLastUpdatedAt": undefined, "frontMatter": {}, @@ -2721,7 +2678,6 @@ exports[`versioned website content 2`] = ` exports[`versioned website content 3`] = ` { "description": "Hello next !", - "draft": false, "editUrl": undefined, "formattedLastUpdatedAt": undefined, "frontMatter": { @@ -2751,7 +2707,6 @@ exports[`versioned website content 3`] = ` exports[`versioned website content 4`] = ` { "description": "Hello 1.0.1 !", - "draft": false, "editUrl": undefined, "formattedLastUpdatedAt": undefined, "frontMatter": { @@ -2781,7 +2736,6 @@ exports[`versioned website content 4`] = ` exports[`versioned website content 5`] = ` { "description": "Baz 1.0.0 ! This will be deleted in next subsequent versions.", - "draft": false, "editUrl": undefined, "formattedLastUpdatedAt": undefined, "frontMatter": {}, @@ -2949,7 +2903,6 @@ exports[`versioned website content: data 1`] = ` } ] }, - \\"draft\\": false, \\"sidebar\\": \\"docs\\", \\"next\\": { \\"title\\": \\"hello\\", @@ -2970,7 +2923,6 @@ exports[`versioned website content: data 1`] = ` \\"frontMatter\\": { \\"slug\\": \\"/\\" }, - \\"draft\\": false, \\"sidebar\\": \\"docs\\", \\"previous\\": { \\"title\\": \\"bar\\", @@ -2990,8 +2942,7 @@ exports[`versioned website content: data 1`] = ` \\"version\\": \\"current\\", \\"frontMatter\\": { \\"slug\\": \\"/absoluteSlug\\" - }, - \\"draft\\": false + } }", "site-docs-slugs-relative-slug-md-d1c.json": "{ \\"unversionedId\\": \\"slugs/relativeSlug\\", @@ -3006,8 +2957,7 @@ exports[`versioned website content: data 1`] = ` \\"version\\": \\"current\\", \\"frontMatter\\": { \\"slug\\": \\"relativeSlug\\" - }, - \\"draft\\": false + } }", "site-docs-slugs-resolved-slug-md-02b.json": "{ \\"unversionedId\\": \\"slugs/resolvedSlug\\", @@ -3022,8 +2972,7 @@ exports[`versioned website content: data 1`] = ` \\"version\\": \\"current\\", \\"frontMatter\\": { \\"slug\\": \\"./hey/ho/../resolvedSlug\\" - }, - \\"draft\\": false + } }", "site-docs-slugs-try-to-escape-slug-md-70d.json": "{ \\"unversionedId\\": \\"slugs/tryToEscapeSlug\\", @@ -3038,8 +2987,7 @@ exports[`versioned website content: data 1`] = ` \\"version\\": \\"current\\", \\"frontMatter\\": { \\"slug\\": \\"../../../../../../../../tryToEscapeSlug\\" - }, - \\"draft\\": false + } }", "site-i-18-n-en-docusaurus-plugin-content-docs-version-1-0-0-hello-md-fe5.json": "{ \\"unversionedId\\": \\"hello\\", @@ -3055,7 +3003,6 @@ exports[`versioned website content: data 1`] = ` \\"frontMatter\\": { \\"slug\\": \\"/\\" }, - \\"draft\\": false, \\"sidebar\\": \\"version-1.0.0/docs\\", \\"previous\\": { \\"title\\": \\"baz\\", @@ -3076,7 +3023,6 @@ exports[`versioned website content: data 1`] = ` \\"frontMatter\\": { \\"slug\\": \\"barSlug\\" }, - \\"draft\\": false, \\"sidebar\\": \\"version-1.0.0/docs\\", \\"next\\": { \\"title\\": \\"baz\\", @@ -3095,7 +3041,6 @@ exports[`versioned website content: data 1`] = ` \\"tags\\": [], \\"version\\": \\"1.0.0\\", \\"frontMatter\\": {}, - \\"draft\\": false, \\"sidebar\\": \\"version-1.0.0/docs\\", \\"previous\\": { \\"title\\": \\"bar\\", @@ -3118,7 +3063,6 @@ exports[`versioned website content: data 1`] = ` \\"tags\\": [], \\"version\\": \\"1.0.1\\", \\"frontMatter\\": {}, - \\"draft\\": false, \\"sidebar\\": \\"VersionedSideBarNameDoesNotMatter/docs\\", \\"next\\": { \\"title\\": \\"hello\\", @@ -3139,7 +3083,6 @@ exports[`versioned website content: data 1`] = ` \\"frontMatter\\": { \\"slug\\": \\"/\\" }, - \\"draft\\": false, \\"sidebar\\": \\"VersionedSideBarNameDoesNotMatter/docs\\", \\"previous\\": { \\"title\\": \\"bar\\", @@ -3160,7 +3103,6 @@ exports[`versioned website content: data 1`] = ` \\"frontMatter\\": { \\"slug\\": \\"/rootAbsoluteSlug\\" }, - \\"draft\\": false, \\"sidebar\\": \\"version-1.0.1/docs\\" }", "site-versioned-docs-version-with-slugs-root-relative-slug-md-32a.json": "{ @@ -3176,8 +3118,7 @@ exports[`versioned website content: data 1`] = ` \\"version\\": \\"withSlugs\\", \\"frontMatter\\": { \\"slug\\": \\"rootRelativeSlug\\" - }, - \\"draft\\": false + } }", "site-versioned-docs-version-with-slugs-root-resolved-slug-md-aee.json": "{ \\"unversionedId\\": \\"rootResolvedSlug\\", @@ -3192,8 +3133,7 @@ exports[`versioned website content: data 1`] = ` \\"version\\": \\"withSlugs\\", \\"frontMatter\\": { \\"slug\\": \\"./hey/ho/../rootResolvedSlug\\" - }, - \\"draft\\": false + } }", "site-versioned-docs-version-with-slugs-root-try-to-escape-slug-md-b5d.json": "{ \\"unversionedId\\": \\"rootTryToEscapeSlug\\", @@ -3208,8 +3148,7 @@ exports[`versioned website content: data 1`] = ` \\"version\\": \\"withSlugs\\", \\"frontMatter\\": { \\"slug\\": \\"../../../../../../../../rootTryToEscapeSlug\\" - }, - \\"draft\\": false + } }", "site-versioned-docs-version-with-slugs-slugs-absolute-slug-md-47a.json": "{ \\"unversionedId\\": \\"slugs/absoluteSlug\\", @@ -3224,8 +3163,7 @@ exports[`versioned website content: data 1`] = ` \\"version\\": \\"withSlugs\\", \\"frontMatter\\": { \\"slug\\": \\"/absoluteSlug\\" - }, - \\"draft\\": false + } }", "site-versioned-docs-version-with-slugs-slugs-relative-slug-md-a95.json": "{ \\"unversionedId\\": \\"slugs/relativeSlug\\", @@ -3240,8 +3178,7 @@ exports[`versioned website content: data 1`] = ` \\"version\\": \\"withSlugs\\", \\"frontMatter\\": { \\"slug\\": \\"relativeSlug\\" - }, - \\"draft\\": false + } }", "site-versioned-docs-version-with-slugs-slugs-resolved-slug-md-5a1.json": "{ \\"unversionedId\\": \\"slugs/resolvedSlug\\", @@ -3256,8 +3193,7 @@ exports[`versioned website content: data 1`] = ` \\"version\\": \\"withSlugs\\", \\"frontMatter\\": { \\"slug\\": \\"./hey/ho/../resolvedSlug\\" - }, - \\"draft\\": false + } }", "site-versioned-docs-version-with-slugs-slugs-try-to-escape-slug-md-4e1.json": "{ \\"unversionedId\\": \\"slugs/tryToEscapeSlug\\", @@ -3272,8 +3208,7 @@ exports[`versioned website content: data 1`] = ` \\"version\\": \\"withSlugs\\", \\"frontMatter\\": { \\"slug\\": \\"../../../../../../../../tryToEscapeSlug\\" - }, - \\"draft\\": false + } }", "tag-docs-next-tags-bar-tag-1-a8f.json": "{ \\"name\\": \\"barTag 1\\", 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 57c0ad8b7046..fa06585aa47e 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/docs.test.ts +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/docs.test.ts @@ -87,7 +87,7 @@ function createTestUtils({ expectedMetadata: Optional< DocMetadataBase, 'source' | 'lastUpdatedBy' | 'lastUpdatedAt' | 'editUrl' - >, + > | null, ) { const docFile = await readDoc(docFileSource); const metadata = await processDocMetadata({ @@ -96,17 +96,21 @@ function createTestUtils({ context, options, }); - expect(metadata).toEqual({ - lastUpdatedBy: undefined, - lastUpdatedAt: undefined, - editUrl: undefined, - source: path.posix.join( - '@site', - posixPath(path.relative(siteDir, versionMetadata.contentPath)), - posixPath(docFileSource), - ), - ...expectedMetadata, - }); + if (expectedMetadata === null) { + expect(metadata).toBeNull(); + } else { + expect(metadata).toEqual({ + lastUpdatedBy: undefined, + lastUpdatedAt: undefined, + editUrl: undefined, + source: path.posix.join( + '@site', + posixPath(path.relative(siteDir, versionMetadata.contentPath)), + posixPath(docFileSource), + ), + ...expectedMetadata, + }); + } } async function testSlug(docFileSource: string, expectedPermalink: string) { @@ -128,14 +132,16 @@ function createTestUtils({ }[]; sidebars: Sidebars; }> { - const rawDocs = docFiles.map((docFile) => - processDocMetadata({ - docFile, - versionMetadata, - context, - options, - }), - ); + const rawDocs = docFiles + .map((docFile) => + processDocMetadata({ + docFile, + versionMetadata, + context, + options, + }), + ) + .filter(Boolean); const sidebars = await loadSidebars(versionMetadata.sidebarFilePath, { sidebarItemsGenerator: ({defaultSidebarItemsGenerator, ...args}) => defaultSidebarItemsGenerator({...args}), @@ -241,7 +247,6 @@ describe('simple site', () => { pagination_prev: null, }, tags: [], - draft: false, }); await defaultTestUtils.testMeta(path.join('hello.md'), { version: 'current', @@ -269,7 +274,6 @@ describe('simple site', () => { permalink: '/docs/tags/tag-3', }, ], - draft: false, }); }); @@ -319,7 +323,6 @@ describe('simple site', () => { permalink: '/docs/tags/tag2-custom-permalink', }, ], - draft: false, }); }); @@ -341,7 +344,6 @@ describe('simple site', () => { unrelated_front_matter: "won't be part of metadata", }, tags: [], - draft: false, }); }); @@ -394,7 +396,6 @@ describe('simple site', () => { permalink: '/docs/tags/tag2-custom-permalink', }, ], - draft: false, }); expect(editUrlFunction).toHaveBeenCalledTimes(1); @@ -440,7 +441,6 @@ describe('simple site', () => { formattedLastUpdatedAt: '10/14/2018', lastUpdatedBy: 'Author', tags: [], - draft: false, }); }); @@ -449,24 +449,7 @@ describe('simple site', () => { const {defaultTestUtils} = await loadSite(); - await defaultTestUtils.testMeta('draft.md', { - version: 'current', - id: 'draft', - unversionedId: 'draft', - sourceDirName: '.', - permalink: '/docs/draft', - sidebarPosition: undefined, - slug: '/draft', - title: 'draft', - editUrl: undefined, - formattedLastUpdatedAt: undefined, - description: 'This is a draft document', - frontMatter: { - draft: true, - }, - tags: [], - draft: true, - }); + await defaultTestUtils.testMeta('draft.md', null); }); it('docs with slugs', async () => { @@ -649,7 +632,6 @@ describe('versioned site', () => { permalink: '/docs/next/tags/barTag-3-permalink', }, ], - draft: false, }); await currentVersionTestUtils.testMeta(path.join('hello.md'), { id: 'hello', @@ -664,7 +646,6 @@ describe('versioned site', () => { slug: '/', }, tags: [], - draft: false, }); }); @@ -682,7 +663,6 @@ describe('versioned site', () => { frontMatter: {slug: 'barSlug'}, version: '1.0.0', tags: [], - draft: false, }); await version100TestUtils.testMeta(path.join('hello.md'), { id: 'version-1.0.0/hello', @@ -699,7 +679,6 @@ describe('versioned site', () => { source: '@site/i18n/en/docusaurus-plugin-content-docs/version-1.0.0/hello.md', tags: [], - draft: false, }); await version101TestUtils.testMeta(path.join('foo', 'bar.md'), { id: 'version-1.0.1/foo/bar', @@ -712,7 +691,6 @@ describe('versioned site', () => { version: '1.0.1', frontMatter: {}, tags: [], - draft: false, }); await version101TestUtils.testMeta(path.join('hello.md'), { id: 'version-1.0.1/hello', @@ -727,7 +705,6 @@ describe('versioned site', () => { slug: '/', }, tags: [], - draft: false, }); }); @@ -824,7 +801,6 @@ describe('versioned site', () => { '@site/i18n/en/docusaurus-plugin-content-docs/version-1.0.0/hello.md', editUrl: hardcodedEditUrl, tags: [], - draft: false, }); expect(editUrlFunction).toHaveBeenCalledTimes(1); @@ -869,7 +845,6 @@ describe('versioned site', () => { editUrl: 'https://github.com/facebook/docusaurus/edit/main/website/versioned_docs/version-1.0.0/hello.md', tags: [], - draft: false, }); }); @@ -905,7 +880,6 @@ describe('versioned site', () => { editUrl: 'https://github.com/facebook/docusaurus/edit/main/website/docs/hello.md', tags: [], - draft: false, }); }); @@ -942,7 +916,6 @@ describe('versioned site', () => { editUrl: 'https://github.com/facebook/docusaurus/edit/main/website/i18n/fr/docusaurus-plugin-content-docs/version-1.0.0/hello.md', tags: [], - draft: false, }); }); @@ -980,7 +953,6 @@ describe('versioned site', () => { editUrl: 'https://github.com/facebook/docusaurus/edit/main/website/i18n/fr/docusaurus-plugin-content-docs/current/hello.md', tags: [], - draft: false, }); }); }); diff --git a/packages/docusaurus-plugin-content-docs/src/docs.ts b/packages/docusaurus-plugin-content-docs/src/docs.ts index 2e6fca68ebb1..4ad86df6f253 100644 --- a/packages/docusaurus-plugin-content-docs/src/docs.ts +++ b/packages/docusaurus-plugin-content-docs/src/docs.ts @@ -120,7 +120,7 @@ function doProcessDocMetadata({ versionMetadata: VersionMetadata; context: LoadContext; options: MetadataOptions; -}): DocMetadataBase { +}): DocMetadataBase | null { const {source, content, lastUpdate, contentPath, filePath} = docFile; const {siteDir, i18n} = context; @@ -131,8 +131,9 @@ function doProcessDocMetadata({ } = parseMarkdownString(content); const frontMatter = validateDocFrontMatter(unsafeFrontMatter); - const draft = - (frontMatter.draft && process.env.NODE_ENV === 'production') || false; + if ((frontMatter.draft && process.env.NODE_ENV === 'production') || false) { + return null; + } const { custom_edit_url: customEditURL, @@ -263,7 +264,6 @@ function doProcessDocMetadata({ : undefined, sidebarPosition, frontMatter, - draft, }; } @@ -272,7 +272,7 @@ export function processDocMetadata(args: { versionMetadata: VersionMetadata; context: LoadContext; options: MetadataOptions; -}): DocMetadataBase { +}): DocMetadataBase | null { try { return doProcessDocMetadata(args); } catch (err) { diff --git a/packages/docusaurus-plugin-content-docs/src/index.ts b/packages/docusaurus-plugin-content-docs/src/index.ts index a0dc21768960..f9fba8e049a3 100644 --- a/packages/docusaurus-plugin-content-docs/src/index.ts +++ b/packages/docusaurus-plugin-content-docs/src/index.ts @@ -132,7 +132,7 @@ export default async function pluginContentDocs( async loadContent() { async function loadVersionDocsBase( versionMetadata: VersionMetadata, - ): Promise { + ): Promise<(DocMetadataBase | null)[]> { const docFiles = await readVersionDocs(versionMetadata, options); if (docFiles.length === 0) { throw new Error( @@ -158,9 +158,9 @@ export default async function pluginContentDocs( async function doLoadVersion( versionMetadata: VersionMetadata, ): Promise { - const docs: DocMetadataBase[] = await loadVersionDocsBase( - versionMetadata, - ); + const docs = (await loadVersionDocsBase(versionMetadata)).filter( + Boolean, + ) as DocMetadataBase[]; const sidebars = await loadSidebars(versionMetadata.sidebarFilePath, { sidebarItemsGenerator: options.sidebarItemsGenerator, diff --git a/packages/docusaurus-plugin-content-docs/src/plugin-content-docs.d.ts b/packages/docusaurus-plugin-content-docs/src/plugin-content-docs.d.ts index 3087821f24fe..79402240d2f3 100644 --- a/packages/docusaurus-plugin-content-docs/src/plugin-content-docs.d.ts +++ b/packages/docusaurus-plugin-content-docs/src/plugin-content-docs.d.ts @@ -406,8 +406,6 @@ declare module '@docusaurus/plugin-content-docs' { tags: Tag[]; /** Front matter, as-is. */ frontMatter: DocFrontMatter & {[key: string]: unknown}; - /** Is the doc going to be excluded from production builds? */ - draft: boolean; }; export type DocMetadata = DocMetadataBase & diff --git a/packages/docusaurus-plugin-content-docs/src/routes.ts b/packages/docusaurus-plugin-content-docs/src/routes.ts index 0b7f60c7e729..3ef6e60ba146 100644 --- a/packages/docusaurus-plugin-content-docs/src/routes.ts +++ b/packages/docusaurus-plugin-content-docs/src/routes.ts @@ -70,33 +70,31 @@ export async function createDocRoutes({ docItemComponent: string; }): Promise { return Promise.all( - docs - .filter((metadataItem) => !metadataItem.draft) - .map(async (metadataItem) => { - await actions.createData( - // Note that this created data path must be in sync with - // metadataPath provided to mdx-loader. - `${docuHash(metadataItem.source)}.json`, - JSON.stringify(metadataItem, null, 2), - ); + docs.map(async (metadataItem) => { + await actions.createData( + // Note that this created data path must be in sync with + // metadataPath provided to mdx-loader. + `${docuHash(metadataItem.source)}.json`, + JSON.stringify(metadataItem, null, 2), + ); - const docRoute: RouteConfig = { - path: metadataItem.permalink, - component: docItemComponent, - exact: true, - modules: { - content: metadataItem.source, - }, - // Because the parent (DocPage) comp need to access it easily - // This permits to render the sidebar once without unmount/remount - // when navigating (and preserve sidebar state) - ...(metadataItem.sidebar && { - sidebar: metadataItem.sidebar, - }), - }; + const docRoute: RouteConfig = { + path: metadataItem.permalink, + component: docItemComponent, + exact: true, + modules: { + content: metadataItem.source, + }, + // Because the parent (DocPage) comp need to access it easily + // This permits to render the sidebar once without unmount/remount when + // navigating (and preserve sidebar state) + ...(metadataItem.sidebar && { + sidebar: metadataItem.sidebar, + }), + }; - return docRoute; - }), + return docRoute; + }), ); }