diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/__fixtures__/simple-site/docs/draft.md b/packages/docusaurus-plugin-content-docs/src/__tests__/__fixtures__/simple-site/docs/draft.md new file mode 100644 index 0000000000000..dfc31e3f3594f --- /dev/null +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/__fixtures__/simple-site/docs/draft.md @@ -0,0 +1,5 @@ +--- +draft: true +--- + +This is a draft document 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 d8ad2b8a3ee82..7eb72cb4e6baf 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 @@ -13,6 +13,10 @@ Array [ undefined, undefined, ], + Array [ + undefined, + undefined, + ], Array [ Object { "permalink": "/docs/foo/bar", 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 bba2e20e8e5ae..e10649759f923 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 @@ -7,6 +7,7 @@ These sidebar document ids do not exist: Available document ids are: - doc with space +- draft - foo/bar - foo/baz - headingAsTitle @@ -43,6 +44,7 @@ Object { "title": "baz", }, "id": "foo/baz", + "isDraft": false, "lastUpdatedAt": undefined, "lastUpdatedBy": undefined, "next": Object { @@ -91,6 +93,7 @@ Object { "title": "Hello, World !", }, "id": "hello", + "isDraft": false, "lastUpdatedAt": undefined, "lastUpdatedBy": undefined, "next": undefined, @@ -133,6 +136,7 @@ Object { "title": "Bar", }, "id": "foo/bar", + "isDraft": false, "lastUpdatedAt": undefined, "lastUpdatedBy": undefined, "next": undefined, @@ -251,6 +255,11 @@ Object { "path": "/docs/doc with space", "sidebar": undefined, }, + Object { + "id": "draft", + "path": "/docs/draft", + "sidebar": undefined, + }, Object { "id": "foo/bar", "path": "/docs/foo/bar", @@ -375,7 +384,24 @@ Object { \\"permalink\\": \\"/docs/doc with space\\", \\"tags\\": [], \\"version\\": \\"current\\", - \\"frontMatter\\": {} + \\"frontMatter\\": {}, + \\"isDraft\\": false +}", + "site-docs-draft-md-5b1.json": "{ + \\"unversionedId\\": \\"draft\\", + \\"id\\": \\"draft\\", + \\"title\\": \\"draft\\", + \\"description\\": \\"This is a draft document\\", + \\"source\\": \\"@site/docs/draft.md\\", + \\"sourceDirName\\": \\".\\", + \\"slug\\": \\"/draft\\", + \\"permalink\\": \\"/docs/draft\\", + \\"tags\\": [], + \\"version\\": \\"current\\", + \\"frontMatter\\": { + \\"draft\\": true + }, + \\"isDraft\\": false }", "site-docs-foo-bar-md-8c2.json": "{ \\"unversionedId\\": \\"foo/bar\\", @@ -395,6 +421,7 @@ Object { \\"pagination_next\\": null, \\"pagination_prev\\": null }, + \\"isDraft\\": false, \\"sidebar\\": \\"docs\\" }", "site-docs-foo-baz-md-a69.json": "{ @@ -431,6 +458,7 @@ Object { } ] }, + \\"isDraft\\": false, \\"sidebar\\": \\"docs\\", \\"previous\\": { \\"title\\": \\"Bar\\", @@ -453,6 +481,7 @@ Object { \\"tags\\": [], \\"version\\": \\"current\\", \\"frontMatter\\": {}, + \\"isDraft\\": false, \\"sidebar\\": \\"docs\\", \\"previous\\": { \\"title\\": \\"rootTryToEscapeSlug\\", @@ -493,6 +522,7 @@ Object { ], \\"slug\\": \\"/\\" }, + \\"isDraft\\": false, \\"sidebar\\": \\"docs\\", \\"previous\\": { \\"title\\": \\"My heading as title\\", @@ -513,7 +543,8 @@ Object { \\"version\\": \\"current\\", \\"frontMatter\\": { \\"custom_edit_url\\": null - } + }, + \\"isDraft\\": false }", "site-docs-lorem-md-b27.json": "{ \\"unversionedId\\": \\"lorem\\", @@ -530,7 +561,8 @@ Object { \\"frontMatter\\": { \\"custom_edit_url\\": \\"https://github.com/customUrl/docs/lorem.md\\", \\"unrelated_front_matter\\": \\"won't be part of metadata\\" - } + }, + \\"isDraft\\": false }", "site-docs-root-absolute-slug-md-db5.json": "{ \\"unversionedId\\": \\"rootAbsoluteSlug\\", @@ -548,6 +580,7 @@ Object { \\"pagination_next\\": \\"headingAsTitle\\", \\"pagination_prev\\": \\"foo/baz\\" }, + \\"isDraft\\": false, \\"sidebar\\": \\"docs\\", \\"previous\\": { \\"title\\": \\"baz pagination_label\\", @@ -574,6 +607,7 @@ Object { \\"pagination_next\\": \\"headingAsTitle\\", \\"pagination_prev\\": \\"foo/baz\\" }, + \\"isDraft\\": false, \\"sidebar\\": \\"docs\\", \\"previous\\": { \\"title\\": \\"baz pagination_label\\", @@ -600,6 +634,7 @@ Object { \\"pagination_next\\": \\"headingAsTitle\\", \\"pagination_prev\\": \\"foo/baz\\" }, + \\"isDraft\\": false, \\"sidebar\\": \\"docs\\", \\"previous\\": { \\"title\\": \\"baz pagination_label\\", @@ -626,6 +661,7 @@ Object { \\"pagination_next\\": \\"headingAsTitle\\", \\"pagination_prev\\": \\"foo/baz\\" }, + \\"isDraft\\": false, \\"sidebar\\": \\"docs\\", \\"previous\\": { \\"title\\": \\"baz pagination_label\\", @@ -649,7 +685,8 @@ Object { \\"version\\": \\"current\\", \\"frontMatter\\": { \\"slug\\": \\"/absoluteSlug\\" - } + }, + \\"isDraft\\": false }", "site-docs-slugs-relative-slug-md-d1c.json": "{ \\"unversionedId\\": \\"slugs/relativeSlug\\", @@ -664,7 +701,8 @@ Object { \\"version\\": \\"current\\", \\"frontMatter\\": { \\"slug\\": \\"relativeSlug\\" - } + }, + \\"isDraft\\": false }", "site-docs-slugs-resolved-slug-md-02b.json": "{ \\"unversionedId\\": \\"slugs/resolvedSlug\\", @@ -679,7 +717,8 @@ Object { \\"version\\": \\"current\\", \\"frontMatter\\": { \\"slug\\": \\"./hey/ho/../resolvedSlug\\" - } + }, + \\"isDraft\\": false }", "site-docs-slugs-try-to-escape-slug-md-70d.json": "{ \\"unversionedId\\": \\"slugs/tryToEscapeSlug\\", @@ -694,7 +733,8 @@ Object { \\"version\\": \\"current\\", \\"frontMatter\\": { \\"slug\\": \\"../../../../../../../../tryToEscapeSlug\\" - } + }, + \\"isDraft\\": false }", "tag-docs-tags-tag-1-b3f.json": "{ \\"name\\": \\"tag 1\\", @@ -868,6 +908,11 @@ Object { \\"title\\": \\"Hoo hoo, if this path tricks you...\\", \\"description\\": \\"\\" }, + \\"draft\\": { + \\"id\\": \\"draft\\", + \\"title\\": \\"draft\\", + \\"description\\": \\"This is a draft document\\" + }, \\"foo/bar\\": { \\"id\\": \\"foo/bar\\", \\"title\\": \\"Bar\\", @@ -964,6 +1009,11 @@ Object { "path": "/docs/doc with space", "sidebar": undefined, }, + Object { + "id": "draft", + "path": "/docs/draft", + "sidebar": undefined, + }, Object { "id": "foo/bar", "path": "/docs/foo/bar", @@ -1137,6 +1187,14 @@ Array [ }, "path": "/docs/doc with space", }, + Object { + "component": "@theme/DocItem", + "exact": true, + "modules": Object { + "content": "@site/docs/draft.md", + }, + "path": "/docs/draft", + }, Object { "component": "@theme/DocItem", "exact": true, @@ -1377,6 +1435,7 @@ Object { Object { "frontMatter": Object {}, "id": "API/Core APIs/Client API", + "isDraft": false, "sidebarPosition": 0, "source": "@site/docs/3-API/01_Core APIs/0 --- Client API.md", "sourceDirName": "3-API/01_Core APIs", @@ -1385,6 +1444,7 @@ Object { Object { "frontMatter": Object {}, "id": "API/Core APIs/Server API", + "isDraft": false, "sidebarPosition": 1, "source": "@site/docs/3-API/01_Core APIs/1 --- Server API.md", "sourceDirName": "3-API/01_Core APIs", @@ -1393,6 +1453,7 @@ Object { Object { "frontMatter": Object {}, "id": "API/Extension APIs/Plugin API", + "isDraft": false, "sidebarPosition": 0, "source": "@site/docs/3-API/02_Extension APIs/0. Plugin API.md", "sourceDirName": "3-API/02_Extension APIs", @@ -1401,6 +1462,7 @@ Object { Object { "frontMatter": Object {}, "id": "API/Extension APIs/Theme API", + "isDraft": false, "sidebarPosition": 1, "source": "@site/docs/3-API/02_Extension APIs/1. Theme API.md", "sourceDirName": "3-API/02_Extension APIs", @@ -1409,6 +1471,7 @@ Object { Object { "frontMatter": Object {}, "id": "API/api-end", + "isDraft": false, "sidebarPosition": 3, "source": "@site/docs/3-API/03_api-end.md", "sourceDirName": "3-API", @@ -1417,6 +1480,7 @@ Object { Object { "frontMatter": Object {}, "id": "API/api-overview", + "isDraft": false, "sidebarPosition": 0, "source": "@site/docs/3-API/00_api-overview.md", "sourceDirName": "3-API", @@ -1428,6 +1492,7 @@ Object { "sidebar_position": 1, }, "id": "Guides/guide1", + "isDraft": false, "sidebarPosition": 1, "source": "@site/docs/Guides/z-guide1.md", "sourceDirName": "Guides", @@ -1438,6 +1503,7 @@ Object { "id": "guide2", }, "id": "Guides/guide2", + "isDraft": false, "sidebarPosition": 2, "source": "@site/docs/Guides/02-guide2.md", "sourceDirName": "Guides", @@ -1449,6 +1515,7 @@ Object { "sidebar_position": 2.5, }, "id": "Guides/guide2.5", + "isDraft": false, "sidebarPosition": 2.5, "source": "@site/docs/Guides/0-guide2.5.md", "sourceDirName": "Guides", @@ -1460,6 +1527,7 @@ Object { "sidebar_position": 3, }, "id": "Guides/guide3", + "isDraft": false, "sidebarPosition": 3, "source": "@site/docs/Guides/guide3.md", "sourceDirName": "Guides", @@ -1470,6 +1538,7 @@ Object { "id": "guide4", }, "id": "Guides/guide4", + "isDraft": false, "sidebarPosition": undefined, "source": "@site/docs/Guides/a-guide4.md", "sourceDirName": "Guides", @@ -1480,6 +1549,7 @@ Object { "id": "guide5", }, "id": "Guides/guide5", + "isDraft": false, "sidebarPosition": undefined, "source": "@site/docs/Guides/b-guide5.md", "sourceDirName": "Guides", @@ -1488,6 +1558,7 @@ Object { Object { "frontMatter": Object {}, "id": "getting-started", + "isDraft": false, "sidebarPosition": 0, "source": "@site/docs/0-getting-started.md", "sourceDirName": ".", @@ -1496,6 +1567,7 @@ Object { Object { "frontMatter": Object {}, "id": "installation", + "isDraft": false, "sidebarPosition": 1, "source": "@site/docs/1-installation.md", "sourceDirName": ".", @@ -1526,6 +1598,7 @@ Object { "formattedLastUpdatedAt": undefined, "frontMatter": Object {}, "id": "getting-started", + "isDraft": false, "lastUpdatedAt": undefined, "lastUpdatedBy": undefined, "next": Object { @@ -1553,6 +1626,7 @@ Object { "formattedLastUpdatedAt": undefined, "frontMatter": Object {}, "id": "installation", + "isDraft": false, "lastUpdatedAt": undefined, "lastUpdatedBy": undefined, "next": Object { @@ -1586,6 +1660,7 @@ Object { "sidebar_position": 1, }, "id": "Guides/guide1", + "isDraft": false, "lastUpdatedAt": undefined, "lastUpdatedBy": undefined, "next": Object { @@ -1618,6 +1693,7 @@ Object { "id": "guide2", }, "id": "Guides/guide2", + "isDraft": false, "lastUpdatedAt": undefined, "lastUpdatedBy": undefined, "next": Object { @@ -1651,6 +1727,7 @@ Object { "sidebar_position": 2.5, }, "id": "Guides/guide2.5", + "isDraft": false, "lastUpdatedAt": undefined, "lastUpdatedBy": undefined, "next": Object { @@ -1684,6 +1761,7 @@ Object { "sidebar_position": 3, }, "id": "Guides/guide3", + "isDraft": false, "lastUpdatedAt": undefined, "lastUpdatedBy": undefined, "next": Object { @@ -1716,6 +1794,7 @@ Object { "id": "guide4", }, "id": "Guides/guide4", + "isDraft": false, "lastUpdatedAt": undefined, "lastUpdatedBy": undefined, "next": Object { @@ -1748,6 +1827,7 @@ Object { "id": "guide5", }, "id": "Guides/guide5", + "isDraft": false, "lastUpdatedAt": undefined, "lastUpdatedBy": undefined, "next": Object { @@ -1778,6 +1858,7 @@ Object { "formattedLastUpdatedAt": undefined, "frontMatter": Object {}, "id": "API/api-overview", + "isDraft": false, "lastUpdatedAt": undefined, "lastUpdatedBy": undefined, "next": Object { @@ -1808,6 +1889,7 @@ Object { "formattedLastUpdatedAt": undefined, "frontMatter": Object {}, "id": "API/Core APIs/Client API", + "isDraft": false, "lastUpdatedAt": undefined, "lastUpdatedBy": undefined, "next": Object { @@ -1838,6 +1920,7 @@ Object { "formattedLastUpdatedAt": undefined, "frontMatter": Object {}, "id": "API/Core APIs/Server API", + "isDraft": false, "lastUpdatedAt": undefined, "lastUpdatedBy": undefined, "next": Object { @@ -1868,6 +1951,7 @@ Object { "formattedLastUpdatedAt": undefined, "frontMatter": Object {}, "id": "API/Extension APIs/Plugin API", + "isDraft": false, "lastUpdatedAt": undefined, "lastUpdatedBy": undefined, "next": Object { @@ -1898,6 +1982,7 @@ Object { "formattedLastUpdatedAt": undefined, "frontMatter": Object {}, "id": "API/Extension APIs/Theme API", + "isDraft": false, "lastUpdatedAt": undefined, "lastUpdatedBy": undefined, "next": Object { @@ -1928,6 +2013,7 @@ Object { "formattedLastUpdatedAt": undefined, "frontMatter": Object {}, "id": "API/api-end", + "isDraft": false, "lastUpdatedAt": undefined, "lastUpdatedBy": undefined, "next": undefined, @@ -2107,6 +2193,7 @@ Object { "formattedLastUpdatedAt": undefined, "frontMatter": Object {}, "id": "API/api-end", + "isDraft": false, "lastUpdatedAt": undefined, "lastUpdatedBy": undefined, "next": Object { @@ -2134,6 +2221,7 @@ Object { "formattedLastUpdatedAt": undefined, "frontMatter": Object {}, "id": "API/api-overview", + "isDraft": false, "lastUpdatedAt": undefined, "lastUpdatedBy": undefined, "next": Object { @@ -2164,6 +2252,7 @@ Object { "formattedLastUpdatedAt": undefined, "frontMatter": Object {}, "id": "API/Extension APIs/Plugin API", + "isDraft": false, "lastUpdatedAt": undefined, "lastUpdatedBy": undefined, "next": Object { @@ -2194,6 +2283,7 @@ Object { "formattedLastUpdatedAt": undefined, "frontMatter": Object {}, "id": "API/Extension APIs/Theme API", + "isDraft": false, "lastUpdatedAt": undefined, "lastUpdatedBy": undefined, "next": undefined, @@ -2255,6 +2345,7 @@ Object { "title": "Team title translated", }, "id": "team", + "isDraft": false, "lastUpdatedAt": undefined, "lastUpdatedBy": undefined, "next": undefined, @@ -2279,6 +2370,7 @@ Object { "formattedLastUpdatedAt": undefined, "frontMatter": Object {}, "id": "version-1.0.0/team", + "isDraft": false, "lastUpdatedAt": undefined, "lastUpdatedBy": undefined, "next": undefined, @@ -2332,6 +2424,7 @@ Object { \\"tags\\": [], \\"version\\": \\"1.0.0\\", \\"frontMatter\\": {}, + \\"isDraft\\": false, \\"sidebar\\": \\"version-1.0.0/community\\" }", "site-i-18-n-en-docusaurus-plugin-content-docs-community-current-team-md-7e5.json": "{ @@ -2348,6 +2441,7 @@ Object { \\"frontMatter\\": { \\"title\\": \\"Team title translated\\" }, + \\"isDraft\\": false, \\"sidebar\\": \\"community\\" }", "version-1-0-0-metadata-prop-608.json": "{ @@ -2525,6 +2619,7 @@ Object { ], }, "id": "foo/bar", + "isDraft": false, "lastUpdatedAt": undefined, "lastUpdatedBy": undefined, "next": Object { @@ -2565,6 +2660,7 @@ Object { "formattedLastUpdatedAt": undefined, "frontMatter": Object {}, "id": "version-1.0.1/foo/bar", + "isDraft": false, "lastUpdatedAt": undefined, "lastUpdatedBy": undefined, "next": Object { @@ -2594,6 +2690,7 @@ Object { "slug": "/", }, "id": "hello", + "isDraft": false, "lastUpdatedAt": undefined, "lastUpdatedBy": undefined, "next": undefined, @@ -2623,6 +2720,7 @@ Object { "slug": "/", }, "id": "version-1.0.1/hello", + "isDraft": false, "lastUpdatedAt": undefined, "lastUpdatedBy": undefined, "next": undefined, @@ -2650,6 +2748,7 @@ Object { "formattedLastUpdatedAt": undefined, "frontMatter": Object {}, "id": "version-1.0.0/foo/baz", + "isDraft": false, "lastUpdatedAt": undefined, "lastUpdatedBy": undefined, "next": Object { @@ -2813,6 +2912,7 @@ Object { } ] }, + \\"isDraft\\": false, \\"sidebar\\": \\"docs\\", \\"next\\": { \\"title\\": \\"hello\\", @@ -2833,6 +2933,7 @@ Object { \\"frontMatter\\": { \\"slug\\": \\"/\\" }, + \\"isDraft\\": false, \\"sidebar\\": \\"docs\\", \\"previous\\": { \\"title\\": \\"bar\\", @@ -2852,7 +2953,8 @@ Object { \\"version\\": \\"current\\", \\"frontMatter\\": { \\"slug\\": \\"/absoluteSlug\\" - } + }, + \\"isDraft\\": false }", "site-docs-slugs-relative-slug-md-d1c.json": "{ \\"unversionedId\\": \\"slugs/relativeSlug\\", @@ -2867,7 +2969,8 @@ Object { \\"version\\": \\"current\\", \\"frontMatter\\": { \\"slug\\": \\"relativeSlug\\" - } + }, + \\"isDraft\\": false }", "site-docs-slugs-resolved-slug-md-02b.json": "{ \\"unversionedId\\": \\"slugs/resolvedSlug\\", @@ -2882,7 +2985,8 @@ Object { \\"version\\": \\"current\\", \\"frontMatter\\": { \\"slug\\": \\"./hey/ho/../resolvedSlug\\" - } + }, + \\"isDraft\\": false }", "site-docs-slugs-try-to-escape-slug-md-70d.json": "{ \\"unversionedId\\": \\"slugs/tryToEscapeSlug\\", @@ -2897,7 +3001,8 @@ Object { \\"version\\": \\"current\\", \\"frontMatter\\": { \\"slug\\": \\"../../../../../../../../tryToEscapeSlug\\" - } + }, + \\"isDraft\\": false }", "site-i-18-n-en-docusaurus-plugin-content-docs-version-1-0-0-hello-md-fe5.json": "{ \\"unversionedId\\": \\"hello\\", @@ -2913,6 +3018,7 @@ Object { \\"frontMatter\\": { \\"slug\\": \\"/\\" }, + \\"isDraft\\": false, \\"sidebar\\": \\"version-1.0.0/docs\\", \\"previous\\": { \\"title\\": \\"baz\\", @@ -2933,6 +3039,7 @@ Object { \\"frontMatter\\": { \\"slug\\": \\"barSlug\\" }, + \\"isDraft\\": false, \\"sidebar\\": \\"version-1.0.0/docs\\", \\"next\\": { \\"title\\": \\"baz\\", @@ -2951,6 +3058,7 @@ Object { \\"tags\\": [], \\"version\\": \\"1.0.0\\", \\"frontMatter\\": {}, + \\"isDraft\\": false, \\"sidebar\\": \\"version-1.0.0/docs\\", \\"previous\\": { \\"title\\": \\"bar\\", @@ -2973,6 +3081,7 @@ Object { \\"tags\\": [], \\"version\\": \\"1.0.1\\", \\"frontMatter\\": {}, + \\"isDraft\\": false, \\"sidebar\\": \\"VersionedSideBarNameDoesNotMatter/docs\\", \\"next\\": { \\"title\\": \\"hello\\", @@ -2993,6 +3102,7 @@ Object { \\"frontMatter\\": { \\"slug\\": \\"/\\" }, + \\"isDraft\\": false, \\"sidebar\\": \\"VersionedSideBarNameDoesNotMatter/docs\\", \\"previous\\": { \\"title\\": \\"bar\\", @@ -3013,6 +3123,7 @@ Object { \\"frontMatter\\": { \\"slug\\": \\"/rootAbsoluteSlug\\" }, + \\"isDraft\\": false, \\"sidebar\\": \\"version-1.0.1/docs\\" }", "site-versioned-docs-version-with-slugs-root-relative-slug-md-32a.json": "{ @@ -3028,7 +3139,8 @@ Object { \\"version\\": \\"withSlugs\\", \\"frontMatter\\": { \\"slug\\": \\"rootRelativeSlug\\" - } + }, + \\"isDraft\\": false }", "site-versioned-docs-version-with-slugs-root-resolved-slug-md-aee.json": "{ \\"unversionedId\\": \\"rootResolvedSlug\\", @@ -3043,7 +3155,8 @@ Object { \\"version\\": \\"withSlugs\\", \\"frontMatter\\": { \\"slug\\": \\"./hey/ho/../rootResolvedSlug\\" - } + }, + \\"isDraft\\": false }", "site-versioned-docs-version-with-slugs-root-try-to-escape-slug-md-b5d.json": "{ \\"unversionedId\\": \\"rootTryToEscapeSlug\\", @@ -3058,7 +3171,8 @@ Object { \\"version\\": \\"withSlugs\\", \\"frontMatter\\": { \\"slug\\": \\"../../../../../../../../rootTryToEscapeSlug\\" - } + }, + \\"isDraft\\": false }", "site-versioned-docs-version-with-slugs-slugs-absolute-slug-md-47a.json": "{ \\"unversionedId\\": \\"slugs/absoluteSlug\\", @@ -3073,7 +3187,8 @@ Object { \\"version\\": \\"withSlugs\\", \\"frontMatter\\": { \\"slug\\": \\"/absoluteSlug\\" - } + }, + \\"isDraft\\": false }", "site-versioned-docs-version-with-slugs-slugs-relative-slug-md-a95.json": "{ \\"unversionedId\\": \\"slugs/relativeSlug\\", @@ -3088,7 +3203,8 @@ Object { \\"version\\": \\"withSlugs\\", \\"frontMatter\\": { \\"slug\\": \\"relativeSlug\\" - } + }, + \\"isDraft\\": false }", "site-versioned-docs-version-with-slugs-slugs-resolved-slug-md-5a1.json": "{ \\"unversionedId\\": \\"slugs/resolvedSlug\\", @@ -3103,7 +3219,8 @@ Object { \\"version\\": \\"withSlugs\\", \\"frontMatter\\": { \\"slug\\": \\"./hey/ho/../resolvedSlug\\" - } + }, + \\"isDraft\\": false }", "site-versioned-docs-version-with-slugs-slugs-try-to-escape-slug-md-4e1.json": "{ \\"unversionedId\\": \\"slugs/tryToEscapeSlug\\", @@ -3118,7 +3235,8 @@ Object { \\"version\\": \\"withSlugs\\", \\"frontMatter\\": { \\"slug\\": \\"../../../../../../../../tryToEscapeSlug\\" - } + }, + \\"isDraft\\": false }", "tag-docs-next-tags-bar-tag-1-a8f.json": "{ \\"name\\": \\"barTag 1\\", diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/docFrontMatter.test.ts b/packages/docusaurus-plugin-content-docs/src/__tests__/docFrontMatter.test.ts index 861a0b711fa04..e152e2afd457d 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/docFrontMatter.test.ts +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/docFrontMatter.test.ts @@ -359,3 +359,19 @@ describe('validateDocFrontMatter toc min/max consistency', () => { ], }); }); + +describe('validateDocFrontMatter draft', () => { + testField({ + prefix: 'draft', + validFrontMatters: [{draft: true}, {draft: false}], + convertibleFrontMatter: [ + [{draft: 'true'}, {draft: true}], + [{draft: 'false'}, {draft: false}], + ], + invalidFrontMatters: [ + [{draft: 'yes'}, 'must be a boolean'], + [{draft: 'no'}, 'must be a boolean'], + [{draft: ''}, 'must be a boolean'], + ], + }); +}); 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 f00525b88ea7d..0d67c267748c0 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/docs.test.ts +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/docs.test.ts @@ -205,6 +205,7 @@ describe('simple site', () => { 'rootTryToEscapeSlug.md', 'headingAsTitle.md', 'doc with space.md', + 'draft.md', 'foo/bar.md', 'foo/baz.md', 'slugs/absoluteSlug.md', @@ -234,6 +235,7 @@ describe('simple site', () => { pagination_prev: null, }, tags: [], + isDraft: false, }); await defaultTestUtils.testMeta(path.join('hello.md'), { version: 'current', @@ -261,6 +263,7 @@ describe('simple site', () => { permalink: '/docs/tags/tag-3', }, ], + isDraft: false, }); }); @@ -310,6 +313,7 @@ describe('simple site', () => { permalink: '/docs/tags/tag2-custom-permalink', }, ], + isDraft: false, }); }); @@ -331,6 +335,7 @@ describe('simple site', () => { unrelated_front_matter: "won't be part of metadata", }, tags: [], + isDraft: false, }); }); @@ -383,6 +388,7 @@ describe('simple site', () => { permalink: '/docs/tags/tag2-custom-permalink', }, ], + isDraft: false, }); expect(editUrlFunction).toHaveBeenCalledTimes(1); @@ -428,6 +434,32 @@ describe('simple site', () => { formattedLastUpdatedAt: '10/14/2018', lastUpdatedBy: 'Author', tags: [], + isDraft: false, + }); + }); + + test('docs with draft frontmatter', async () => { + process.env.NODE_ENV = 'production'; + + 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: [], + isDraft: true, }); }); @@ -610,6 +642,7 @@ describe('versioned site', () => { permalink: '/docs/next/tags/barTag-3-permalink', }, ], + isDraft: false, }); await currentVersionTestUtils.testMeta(path.join('hello.md'), { id: 'hello', @@ -624,6 +657,7 @@ describe('versioned site', () => { slug: '/', }, tags: [], + isDraft: false, }); }); @@ -641,6 +675,7 @@ describe('versioned site', () => { frontMatter: {slug: 'barSlug'}, version: '1.0.0', tags: [], + isDraft: false, }); await version100TestUtils.testMeta(path.join('hello.md'), { id: 'version-1.0.0/hello', @@ -657,6 +692,7 @@ describe('versioned site', () => { source: '@site/i18n/en/docusaurus-plugin-content-docs/version-1.0.0/hello.md', tags: [], + isDraft: false, }); await version101TestUtils.testMeta(path.join('foo', 'bar.md'), { id: 'version-1.0.1/foo/bar', @@ -669,6 +705,7 @@ describe('versioned site', () => { version: '1.0.1', frontMatter: {}, tags: [], + isDraft: false, }); await version101TestUtils.testMeta(path.join('hello.md'), { id: 'version-1.0.1/hello', @@ -683,6 +720,7 @@ describe('versioned site', () => { slug: '/', }, tags: [], + isDraft: false, }); }); @@ -779,6 +817,7 @@ describe('versioned site', () => { '@site/i18n/en/docusaurus-plugin-content-docs/version-1.0.0/hello.md', editUrl: hardcodedEditUrl, tags: [], + isDraft: false, }); expect(editUrlFunction).toHaveBeenCalledTimes(1); @@ -823,6 +862,7 @@ describe('versioned site', () => { editUrl: 'https://github.com/facebook/docusaurus/edit/main/website/versioned_docs/version-1.0.0/hello.md', tags: [], + isDraft: false, }); }); @@ -858,6 +898,7 @@ describe('versioned site', () => { editUrl: 'https://github.com/facebook/docusaurus/edit/main/website/docs/hello.md', tags: [], + isDraft: false, }); }); @@ -894,6 +935,7 @@ 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: [], + isDraft: false, }); }); @@ -931,6 +973,7 @@ describe('versioned site', () => { editUrl: 'https://github.com/facebook/docusaurus/edit/main/website/i18n/fr/docusaurus-plugin-content-docs/current/hello.md', tags: [], + isDraft: false, }); }); }); diff --git a/packages/docusaurus-plugin-content-docs/src/docFrontMatter.ts b/packages/docusaurus-plugin-content-docs/src/docFrontMatter.ts index 432c9ea7aa9fb..17735376d9349 100644 --- a/packages/docusaurus-plugin-content-docs/src/docFrontMatter.ts +++ b/packages/docusaurus-plugin-content-docs/src/docFrontMatter.ts @@ -37,6 +37,7 @@ const DocFrontMatterSchema = Joi.object({ parse_number_prefixes: Joi.boolean(), pagination_next: Joi.string().allow(null), pagination_prev: Joi.string().allow(null), + draft: Joi.boolean(), ...FrontMatterTOCHeadingLevels, }).unknown(); diff --git a/packages/docusaurus-plugin-content-docs/src/docs.ts b/packages/docusaurus-plugin-content-docs/src/docs.ts index 79f692b16931a..92db958400fe5 100644 --- a/packages/docusaurus-plugin-content-docs/src/docs.ts +++ b/packages/docusaurus-plugin-content-docs/src/docs.ts @@ -136,6 +136,9 @@ function doProcessDocMetadata({ } = parseMarkdownString(content); const frontMatter = validateDocFrontMatter(unsafeFrontMatter); + const isDraft = + (frontMatter.draft && process.env.NODE_ENV === 'production') || false; + const { custom_edit_url: customEditURL, @@ -265,6 +268,7 @@ function doProcessDocMetadata({ : undefined, sidebarPosition, frontMatter, + isDraft, }; } diff --git a/packages/docusaurus-plugin-content-docs/src/routes.ts b/packages/docusaurus-plugin-content-docs/src/routes.ts index e86b42f5718ef..07631f1c7470c 100644 --- a/packages/docusaurus-plugin-content-docs/src/routes.ts +++ b/packages/docusaurus-plugin-content-docs/src/routes.ts @@ -94,31 +94,33 @@ export async function createDocRoutes({ docItemComponent: string; }): Promise { return Promise.all( - 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, - }), - }; - - return docRoute; - }), + docs + .filter((metadataItem) => !metadataItem.isDraft) + .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, + }), + }; + + return docRoute; + }), ); } diff --git a/packages/docusaurus-plugin-content-docs/src/sidebars/__tests__/generator.test.ts b/packages/docusaurus-plugin-content-docs/src/sidebars/__tests__/generator.test.ts index dfda57ad80701..972885c0044fc 100644 --- a/packages/docusaurus-plugin-content-docs/src/sidebars/__tests__/generator.test.ts +++ b/packages/docusaurus-plugin-content-docs/src/sidebars/__tests__/generator.test.ts @@ -589,4 +589,46 @@ describe('DefaultSidebarItemsGenerator', () => { }, ] as Sidebar); }); + + test('excludes items for draft docs', async () => { + const sidebarSlice = await DefaultSidebarItemsGenerator({ + numberPrefixParser: DefaultNumberPrefixParser, + item: { + type: 'autogenerated', + dirName: '.', + }, + version: { + versionName: 'current', + contentPath: '', + }, + docs: [ + { + id: 'doc1', + source: 'doc1.md', + sourceDirName: '.', + sidebarPosition: 1, + frontMatter: { + draft: true, + }, + isDraft: true, + }, + { + id: 'doc2', + source: 'doc2.md', + sourceDirName: '.', + sidebarPosition: 2, + frontMatter: { + draft: false, + }, + isDraft: false, + }, + ], + options: { + sidebarCollapsed: true, + sidebarCollapsible: true, + }, + }); + + expect(sidebarSlice).toEqual([{type: 'doc', id: 'doc2'}] as Sidebar); + }); }); diff --git a/packages/docusaurus-plugin-content-docs/src/sidebars/__tests__/processor.test.ts b/packages/docusaurus-plugin-content-docs/src/sidebars/__tests__/processor.test.ts index 68d65a2d3a2c8..e72f67b7f103c 100644 --- a/packages/docusaurus-plugin-content-docs/src/sidebars/__tests__/processor.test.ts +++ b/packages/docusaurus-plugin-content-docs/src/sidebars/__tests__/processor.test.ts @@ -249,4 +249,33 @@ describe('processSidebars', () => { ], } as ProcessedSidebars); }); + + test('excludes items for draft docs', async () => { + const unprocessedSidebars: NormalizedSidebars = { + someSidebar: [ + {type: 'doc', id: 'doc1'}, + {type: 'doc', id: 'doc2'}, + ], + }; + + const processedSidebar = await testProcessSidebars( + unprocessedSidebars, + {}, + { + docs: [ + { + id: 'doc1', + isDraft: true, + }, + { + id: 'doc2', + isDraft: false, + }, + ], + }, + ); + expect(processedSidebar).toEqual({ + someSidebar: [{type: 'doc', id: 'doc2'}], + }); + }); }); diff --git a/packages/docusaurus-plugin-content-docs/src/sidebars/generator.ts b/packages/docusaurus-plugin-content-docs/src/sidebars/generator.ts index 03239e3ec4a67..840ab5c7df463 100644 --- a/packages/docusaurus-plugin-content-docs/src/sidebars/generator.ts +++ b/packages/docusaurus-plugin-content-docs/src/sidebars/generator.ts @@ -51,7 +51,8 @@ export const DefaultSidebarItemsGenerator: SidebarItemsGenerator = async ({ item: {dirName: autogenDir}, categoriesMetadata, }) => { - const docsById = createDocsByIdIndex(allDocs); + const visibleDocs = allDocs.filter((doc) => !doc.isDraft); + const docsById = createDocsByIdIndex(visibleDocs); const findDoc = (docId: string): SidebarItemsGeneratorDoc | undefined => docsById[docId]; const getDoc = (docId: string): SidebarItemsGeneratorDoc => { @@ -81,7 +82,7 @@ export const DefaultSidebarItemsGenerator: SidebarItemsGenerator = async ({ doc.sourceDirName.startsWith(addTrailingSlash(autogenDir)) ); } - const docs = allDocs.filter(isInAutogeneratedDir); + const docs = visibleDocs.filter(isInAutogeneratedDir); if (docs.length === 0) { logger.warn`No docs found in path=${autogenDir}: can't auto-generate a sidebar.`; diff --git a/packages/docusaurus-plugin-content-docs/src/sidebars/processor.ts b/packages/docusaurus-plugin-content-docs/src/sidebars/processor.ts index f7432222e448a..7f9919ffe3150 100644 --- a/packages/docusaurus-plugin-content-docs/src/sidebars/processor.ts +++ b/packages/docusaurus-plugin-content-docs/src/sidebars/processor.ts @@ -35,6 +35,7 @@ function toSidebarItemsGeneratorDoc( 'source', 'sourceDirName', 'sidebarPosition', + 'isDraft', ]); } @@ -98,6 +99,12 @@ async function processSidebar( if (item.type === 'autogenerated') { return processAutoGeneratedItem(item); } + if ( + item.type === 'doc' && + docs.find((doc) => doc.id === item.id)?.isDraft + ) { + return []; + } return [item]; } diff --git a/packages/docusaurus-plugin-content-docs/src/sidebars/types.ts b/packages/docusaurus-plugin-content-docs/src/sidebars/types.ts index 620344c4ed489..f9ba244de1175 100644 --- a/packages/docusaurus-plugin-content-docs/src/sidebars/types.ts +++ b/packages/docusaurus-plugin-content-docs/src/sidebars/types.ts @@ -230,6 +230,7 @@ export type SidebarItemsGeneratorDoc = Pick< | 'source' | 'sourceDirName' | 'sidebarPosition' + | 'isDraft' >; export type SidebarItemsGeneratorVersion = Pick< VersionMetadata, diff --git a/packages/docusaurus-plugin-content-docs/src/types.ts b/packages/docusaurus-plugin-content-docs/src/types.ts index e4a96f1079498..328fa499185cc 100644 --- a/packages/docusaurus-plugin-content-docs/src/types.ts +++ b/packages/docusaurus-plugin-content-docs/src/types.ts @@ -66,6 +66,7 @@ export type DocFrontMatter = { toc_max_heading_level?: number; pagination_next?: string | null; pagination_prev?: string | null; + draft?: boolean; }; export type DocMetadataBase = LastUpdateData & { @@ -82,6 +83,7 @@ export type DocMetadataBase = LastUpdateData & { editUrl?: string | null; tags: Tag[]; frontMatter: DocFrontMatter & Record; + isDraft: boolean; }; export type DocNavLink = { diff --git a/website/docs/api/plugins/plugin-content-docs.md b/website/docs/api/plugins/plugin-content-docs.md index 0c52f97ad252e..3bb140f556125 100644 --- a/website/docs/api/plugins/plugin-content-docs.md +++ b/website/docs/api/plugins/plugin-content-docs.md @@ -233,6 +233,7 @@ Accepted fields: | `image` | `string` | `undefined` | Cover or thumbnail image that will be used when displaying the link to your post. | | `slug` | `string` | File path | Allows to customize the document url (`//`). Support multiple patterns: `slug: my-doc`, `slug: /my/path/myDoc`, `slug: /`. | | `tags` | `Tag[]` | `undefined` | A list of strings or objects of two string fields `label` and `permalink` to tag to your docs. | +| `draft` | `boolean` | `false` | Whether to exclude this document from production builds and sidebars. |