mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 15:47:23 +02:00
feat(docs,blog,pages): add support for "unlisted" front matter - hide md content in production (#8004)
Co-authored-by: sebastienlorber <lorber.sebastien@gmail.com>
This commit is contained in:
parent
7a023a2c41
commit
683ba3d2a0
131 changed files with 2449 additions and 303 deletions
|
@ -28,6 +28,16 @@ exports[`validation schemas admonitionsSchema: for value={"unknownAttribute":"va
|
|||
|
||||
exports[`validation schemas admonitionsSchema: for value=3 1`] = `""value" does not look like a valid admonitions config"`;
|
||||
|
||||
exports[`validation schemas contentVisibilitySchema: for value={"draft":"bad string"} 1`] = `""draft" must be a boolean"`;
|
||||
|
||||
exports[`validation schemas contentVisibilitySchema: for value={"draft":42} 1`] = `""draft" must be a boolean"`;
|
||||
|
||||
exports[`validation schemas contentVisibilitySchema: for value={"draft":true,"unlisted":true} 1`] = `"Can't be draft and unlisted at the same time."`;
|
||||
|
||||
exports[`validation schemas contentVisibilitySchema: for value={"unlisted":"bad string"} 1`] = `""unlisted" must be a boolean"`;
|
||||
|
||||
exports[`validation schemas contentVisibilitySchema: for value={"unlisted":42} 1`] = `""unlisted" must be a boolean"`;
|
||||
|
||||
exports[`validation schemas pathnameSchema: for value="foo" 1`] = `""value" is not a valid pathname. Pathname should start with slash and not contain any domain or query string."`;
|
||||
|
||||
exports[`validation schemas pathnameSchema: for value="https://github.com/foo" 1`] = `""value" is not a valid pathname. Pathname should start with slash and not contain any domain or query string."`;
|
||||
|
|
|
@ -14,6 +14,7 @@ import {
|
|||
PluginIdSchema,
|
||||
URISchema,
|
||||
PathnameSchema,
|
||||
ContentVisibilitySchema,
|
||||
} from '../validationSchemas';
|
||||
|
||||
function createTestHelpers({
|
||||
|
@ -166,4 +167,28 @@ describe('validation schemas', () => {
|
|||
testFail('foo');
|
||||
testFail('https://github.com/foo');
|
||||
});
|
||||
|
||||
it('contentVisibilitySchema', () => {
|
||||
const {testFail, testOK} = createTestHelpers({
|
||||
schema: ContentVisibilitySchema,
|
||||
});
|
||||
|
||||
testOK({});
|
||||
testOK({draft: false});
|
||||
testOK({draft: true});
|
||||
testOK({unlisted: false});
|
||||
testOK({unlisted: true});
|
||||
|
||||
testOK({draft: false, unlisted: false});
|
||||
testOK({draft: true, unlisted: false});
|
||||
testOK({draft: false, unlisted: true});
|
||||
testOK({draft: true, unlisted: undefined});
|
||||
testOK({draft: undefined, unlisted: true});
|
||||
|
||||
testFail({draft: 'bad string'});
|
||||
testFail({draft: 42});
|
||||
testFail({unlisted: 'bad string'});
|
||||
testFail({unlisted: 42});
|
||||
testFail({draft: true, unlisted: true});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -24,4 +24,5 @@ export {
|
|||
PathnameSchema,
|
||||
FrontMatterTagsSchema,
|
||||
FrontMatterTOCHeadingLevels,
|
||||
ContentVisibilitySchema,
|
||||
} from './validationSchemas';
|
||||
|
|
|
@ -126,3 +126,26 @@ export const FrontMatterTOCHeadingLevels = {
|
|||
}),
|
||||
toc_max_heading_level: JoiFrontMatter.number().min(2).max(6),
|
||||
};
|
||||
|
||||
export type ContentVisibility = {
|
||||
draft: boolean;
|
||||
unlisted: boolean;
|
||||
};
|
||||
|
||||
export const ContentVisibilitySchema = JoiFrontMatter.object<ContentVisibility>(
|
||||
{
|
||||
draft: JoiFrontMatter.boolean(),
|
||||
unlisted: JoiFrontMatter.boolean(),
|
||||
},
|
||||
)
|
||||
.custom((frontMatter: ContentVisibility, helpers) => {
|
||||
if (frontMatter.draft && frontMatter.unlisted) {
|
||||
return helpers.error('frontMatter.draftAndUnlistedError');
|
||||
}
|
||||
return frontMatter;
|
||||
})
|
||||
.messages({
|
||||
'frontMatter.draftAndUnlistedError':
|
||||
"Can't be draft and unlisted at the same time.",
|
||||
})
|
||||
.unknown();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue