Skip to content

Commit

Permalink
Revert "feat(content-docs): exclude unlisted docs from sidebars"
Browse files Browse the repository at this point in the history
This reverts commit 3eab5b7.
  • Loading branch information
jodyheavener committed Mar 20, 2022
1 parent 9976e6b commit d9039c2
Show file tree
Hide file tree
Showing 13 changed files with 21 additions and 220 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -391,19 +391,3 @@ describe('validateDocFrontMatter draft', () => {
],
});
});

describe('validateDocFrontMatter unlisted', () => {
testField({
prefix: 'unlisted',
validFrontMatters: [{unlisted: true}, {unlisted: false}],
convertibleFrontMatter: [
[{unlisted: 'true'}, {unlisted: true}],
[{unlisted: 'false'}, {unlisted: false}],
],
invalidFrontMatters: [
[{unlisted: 'yes'}, 'must be a boolean'],
[{unlisted: 'no'}, 'must be a boolean'],
[{unlisted: ''}, 'must be a boolean'],
],
});
});
18 changes: 0 additions & 18 deletions packages/docusaurus-plugin-content-docs/src/__tests__/docs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ describe('simple site', () => {
},
tags: [],
isDraft: false,
isUnlisted: false,
});
await defaultTestUtils.testMeta(path.join('hello.md'), {
version: 'current',
Expand Down Expand Up @@ -269,7 +268,6 @@ describe('simple site', () => {
},
],
isDraft: false,
isUnlisted: false,
});
});

Expand Down Expand Up @@ -320,7 +318,6 @@ describe('simple site', () => {
},
],
isDraft: false,
isUnlisted: false,
});
});

Expand All @@ -343,7 +340,6 @@ describe('simple site', () => {
},
tags: [],
isDraft: false,
isUnlisted: false,
});
});

Expand Down Expand Up @@ -397,7 +393,6 @@ describe('simple site', () => {
},
],
isDraft: false,
isUnlisted: false,
});

expect(editUrlFunction).toHaveBeenCalledTimes(1);
Expand Down Expand Up @@ -444,7 +439,6 @@ describe('simple site', () => {
lastUpdatedBy: 'Author',
tags: [],
isDraft: false,
isUnlisted: false,
});
});

Expand All @@ -470,7 +464,6 @@ describe('simple site', () => {
},
tags: [],
isDraft: true,
isUnlisted: false,
});
});

Expand Down Expand Up @@ -654,7 +647,6 @@ describe('versioned site', () => {
},
],
isDraft: false,
isUnlisted: false,
});
await currentVersionTestUtils.testMeta(path.join('hello.md'), {
id: 'hello',
Expand All @@ -670,7 +662,6 @@ describe('versioned site', () => {
},
tags: [],
isDraft: false,
isUnlisted: false,
});
});

Expand All @@ -689,7 +680,6 @@ describe('versioned site', () => {
version: '1.0.0',
tags: [],
isDraft: false,
isUnlisted: false,
});
await version100TestUtils.testMeta(path.join('hello.md'), {
id: 'version-1.0.0/hello',
Expand All @@ -707,7 +697,6 @@ describe('versioned site', () => {
'@site/i18n/en/docusaurus-plugin-content-docs/version-1.0.0/hello.md',
tags: [],
isDraft: false,
isUnlisted: false,
});
await version101TestUtils.testMeta(path.join('foo', 'bar.md'), {
id: 'version-1.0.1/foo/bar',
Expand All @@ -721,7 +710,6 @@ describe('versioned site', () => {
frontMatter: {},
tags: [],
isDraft: false,
isUnlisted: false,
});
await version101TestUtils.testMeta(path.join('hello.md'), {
id: 'version-1.0.1/hello',
Expand All @@ -737,7 +725,6 @@ describe('versioned site', () => {
},
tags: [],
isDraft: false,
isUnlisted: false,
});
});

Expand Down Expand Up @@ -835,7 +822,6 @@ describe('versioned site', () => {
editUrl: hardcodedEditUrl,
tags: [],
isDraft: false,
isUnlisted: false,
});

expect(editUrlFunction).toHaveBeenCalledTimes(1);
Expand Down Expand Up @@ -881,7 +867,6 @@ describe('versioned site', () => {
'https://github.com/facebook/docusaurus/edit/main/website/versioned_docs/version-1.0.0/hello.md',
tags: [],
isDraft: false,
isUnlisted: false,
});
});

Expand Down Expand Up @@ -918,7 +903,6 @@ describe('versioned site', () => {
'https://github.com/facebook/docusaurus/edit/main/website/docs/hello.md',
tags: [],
isDraft: false,
isUnlisted: false,
});
});

Expand Down Expand Up @@ -956,7 +940,6 @@ describe('versioned site', () => {
'https://github.com/facebook/docusaurus/edit/main/website/i18n/fr/docusaurus-plugin-content-docs/version-1.0.0/hello.md',
tags: [],
isDraft: false,
isUnlisted: false,
});
});

Expand Down Expand Up @@ -995,7 +978,6 @@ describe('versioned site', () => {
'https://github.com/facebook/docusaurus/edit/main/website/i18n/fr/docusaurus-plugin-content-docs/current/hello.md',
tags: [],
isDraft: false,
isUnlisted: false,
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ const DocFrontMatterSchema = Joi.object<DocFrontMatter>({
pagination_next: Joi.string().allow(null),
pagination_prev: Joi.string().allow(null),
draft: Joi.boolean(),
unlisted: Joi.boolean(),
...FrontMatterTOCHeadingLevels,
}).unknown();

Expand Down
2 changes: 0 additions & 2 deletions packages/docusaurus-plugin-content-docs/src/docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ function doProcessDocMetadata({

const isDraft =
(frontMatter.draft && process.env.NODE_ENV === 'production') || false;
const isUnlisted = frontMatter.unlisted || false;

const {
custom_edit_url: customEditURL,
Expand Down Expand Up @@ -269,7 +268,6 @@ function doProcessDocMetadata({
sidebarPosition,
frontMatter,
isDraft,
isUnlisted,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -546,46 +546,4 @@ describe('DefaultSidebarItemsGenerator', () => {

expect(sidebarSlice).toEqual([{type: 'doc', id: 'doc2'}] as Sidebar);
});

test('excludes items for unlisted 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: {
unlisted: true,
},
isUnlisted: true,
},
{
id: 'doc2',
source: 'doc2.md',
sourceDirName: '.',
sidebarPosition: 2,
frontMatter: {
unlisted: false,
},
isUnlisted: false,
},
],
options: {
sidebarCollapsed: true,
sidebarCollapsible: true,
},
});

expect(sidebarSlice).toEqual([{type: 'doc', id: 'doc2'}] as Sidebar);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -279,33 +279,4 @@ describe('processSidebars', () => {
someSidebar: [{type: 'doc', id: 'doc2'}],
});
});

test('excludes items for unlisted docs', async () => {
const unprocessedSidebars: NormalizedSidebars = {
someSidebar: [
{type: 'doc', id: 'doc1'},
{type: 'doc', id: 'doc2'},
],
};

const processedSidebar = await testProcessSidebars(
unprocessedSidebars,
{},
{
docs: [
{
id: 'doc1',
isUnlisted: true,
},
{
id: 'doc2',
isUnlisted: false,
},
],
},
);
expect(processedSidebar).toEqual({
someSidebar: [{type: 'doc', id: 'doc2'}],
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {addTrailingSlash, posixPath} from '@docusaurus/utils';
import logger from '@docusaurus/logger';
import path from 'path';
import {createDocsByIdIndex, toCategoryIndexMatcherParam} from '../docs';
import {docIsInvisible} from './utils';

const BreadcrumbSeparator = '/';

Expand Down Expand Up @@ -54,7 +53,7 @@ export const DefaultSidebarItemsGenerator: SidebarItemsGenerator = async ({
item: {dirName: autogenDir},
categoriesMetadata,
}) => {
const visibleDocs = allDocs.filter((doc) => !docIsInvisible(doc));
const visibleDocs = allDocs.filter((doc) => !doc.isDraft);
const docsById = createDocsByIdIndex(visibleDocs);
const findDoc = (docId: string): SidebarItemsGeneratorDoc | undefined =>
docsById[docId];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import type {
SidebarProcessorParams,
CategoryMetadataFile,
} from './types';
import {docIsInvisible} from './utils';
import {DefaultSidebarItemsGenerator} from './generator';
import {validateSidebars} from './validation';
import _ from 'lodash';
Expand All @@ -37,7 +36,6 @@ function toSidebarItemsGeneratorDoc(
'sourceDirName',
'sidebarPosition',
'isDraft',
'isUnlisted',
]);
}

Expand Down Expand Up @@ -103,7 +101,7 @@ async function processSidebar(
}
if (
item.type === 'doc' &&
docIsInvisible(docs.find((doc) => doc.id === item.id))
docs.find((doc) => doc.id === item.id)?.isDraft
) {
return [];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ export type SidebarItemsGeneratorDoc = Pick<
| 'sourceDirName'
| 'sidebarPosition'
| 'isDraft'
| 'isUnlisted'
>;
export type SidebarItemsGeneratorVersion = Pick<
VersionMetadata,
Expand Down
5 changes: 0 additions & 5 deletions packages/docusaurus-plugin-content-docs/src/sidebars/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import type {
SidebarItemConfig,
SidebarItemCategoryWithGeneratedIndex,
SidebarNavigationItem,
SidebarItemsGeneratorDoc,
} from './types';

import _ from 'lodash';
Expand Down Expand Up @@ -387,7 +386,3 @@ export function toNavigationLink(
}
return toDocNavigationLink(getDocById(navigationItem.id));
}

export function docIsInvisible(doc?: SidebarItemsGeneratorDoc): boolean {
return doc ? doc.isDraft || doc.isUnlisted : false;
}
2 changes: 0 additions & 2 deletions packages/docusaurus-plugin-content-docs/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ export type DocFrontMatter = {
pagination_next?: string | null;
pagination_prev?: string | null;
draft?: boolean;
unlisted?: boolean;
};

export type DocMetadataBase = LastUpdateData & {
Expand All @@ -86,7 +85,6 @@ export type DocMetadataBase = LastUpdateData & {
tags: Tag[];
frontMatter: DocFrontMatter & Record<string, unknown>;
isDraft: boolean;
isUnlisted: boolean;
};

export type DocNavLink = {
Expand Down
1 change: 0 additions & 1 deletion website/docs/api/plugins/plugin-content-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ Accepted fields:
| `slug` | `string` | File path | Allows to customize the document url (`/<routeBasePath>/<slug>`). 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. |
| `unlisted` | `boolean` | `false` | Whether to exclude this document from sidebars, while remaining accessible with the direct URL. |

</APITable>

Expand Down

0 comments on commit d9039c2

Please sign in to comment.